Hi,
I have a doubt on the future of CakePHP regarding how will it handle
joins in future releases.
The issue is: When you have several models tied together through
hasMany/belongsTo/hasAndBelongsToMany/hasOne, CakePHP will execute the
database queries all at once, parse them and organise them into an
array.
So it'll likely you'll have something such:
$users[0] = Array( "User" => Array("name" => "My Name", "Remark" =>
array("remark" => "i see it")));
or even
$remarks[0] = Array( "Remarks" => array("remark" => "i see it"),
"User" => array("name" => "My Name"));
OK. That's how CakePHP works nowadays.
I am not a master in MVC concepts and subtleties, but I wonder it
could be a bad thing.
You see, one of the main goals of OO programming is that you write
code that can be changed. So let's suppose you have a model named
User, it'd not be joint to anyone else.
You write a whole application using:
$this->User->find('all', .... &c);
For some wicked reason that shall remain rather vague, you do _not_
specify the recursiveness of these "finds", and therefore CakePHP will
default it to "1", which brings all model's data and additionally the
first degree of joins. As this model has no such degree, it'll return
only User's data.
Yet this system is not complete, and at some point it demands that a
Remark system to be attached to User model.
The programmer goes on app/model/User.php and adds a hasMany entry
into User, and a belongsTo entry into Remark.
Suddenly, according to CakePHP's current logic, ALL finds will return
not only User's data but also it'll return all the Remark entries each
User has stored. All over the system. You ought to grep the source for
"$this->User->" and write down a "$this->User->recursive=0;" all over
the source code.
So far, no news. Here's the catch:
Should CakePHP model code return something like:
$users[0] = Array( "User" => Array("name" => "My Name", "Remark" =>
new RemarkSpecialJoinObjectWhichSeeksInformationOnFirstCall($user
['User']['id']));
On the views reading $users and User data only, it'll imply neither a
change on memory consumption nor SQL performance, because although
User comunicates with Remark, the view would not demand the Remark
entries, thus avoiding one database seek. They'd never read the Remark
dimension, and therefore the database would never be read too.
On the other hand, on the new code which needs both User's and
Remark's entries, the object on its own would understand the situation
and seek further data.
Does anyone know if CakePHP will solve this problem in future
releases?
Thanks,
Dérico Filho
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---