Edit 3
After reading the load on the boat, I really do not think that with the ORM or the system in general, it is possible to build relationships of organized objects, as I want, in the fewer queries that I use. If someone can serve as an example that this is possible, I would kiss you.
In Edit 2 Nested for loops, I think the best solution works
Total_queries = 1 + 2(Slides_in_project) + Shapes_in_project
| | \
Query to get project | \
| \
Query to get slides and double because of points \
\
Get all the shapes in the project
I would like the best example, because to complete simple projects I would probably execute 200-500 queries. This is bad.
Edit 2
, - , , , "", . , where_related , , , , ORM . , , foreach, . .
,
function get_project_points($link_id)
{
echo "<pre>";
foreach($this->where('link_id', $link_id)->get()->slide->where_related('project', 'id', $this)->get() as $slide){
echo $slide->id."<br>";
foreach($slide->shape->where_related('slide', 'id', $slide->id)->get() as $shape){
echo "\t".$shape->id."<br>";
foreach ($shape->point->where_related('shape', 'id', $shape->id)->get() as $point) {
echo "\t\t".$point->id."<br>";
}
}
}
}
, , , /.
, , , , .
$this->where('link_id', $link_id)->get()
->slide->where_related('project', 'id', $this)->get()
->shape->where_related('slide', 'id', $slide->id)->get()
->point->where_related('shape', 'id', $shape->id)->get()
, , , foreach, , , - foreach
, , foreach 63 , . . .
__________ 1
, , , . , , , - ORM.
slides project. , , . , . .
class Project extends DataMapper {
var $has_many = array("slide");
function get_project_slides($link_id)
{
$this->where('link_id', $link_id)
->where_related('slides', 'project_id'
$this->where('link_id', $link_id)->get()->id
)
->get();
}
}
, , .
... ORM?
ORM , , .
DataMapper ORM CodeIgniter. , , , , .
+-----------+ +------------+ +---------+ +----------+
| projects | | slides | | shapes | | points |
+-----------+ +------------+ +---------+ +----------+
| id | | id | | id | | id |
+-----------+ | project_id | |slide_id | | shape_id |
+------------+ +---------+ | x |
| y |
+----------+
-
project.php
class Project extends DataMapper {
var $has_many = array("slide");
}
slide.php
<?php
class Slide extends DataMapper {
var $has_many = array("shape");
var $has_one = array("project");
}
shape.php
<?php
class Shape extends DataMapper {
var $has_many = array("point");
var $has_one = array("slide");
}
point.php
<?php
class Point extends DataMapper {
var $has_one = array("shape");
}
β β β
? ORM, , ORM-? , 1, ?
, , . , , , .