Hello,
I've got problems really understanding how models are instantiated.
Consider the following models:
- Place hasMany Event (and Event belongsTo Place)
- Event hasMany Photoset (and Photoset belongsTo Event)
Then consider PlacesController:
class PlacesController extends AppController
{
var $uses = array('Place', 'Photoset');
function view($id)
{
// Get all data of this place, with recursive depth 2. So we
will get all events that belong to this place,
// and all photosets that belong to these events. Assume that
we don't want any Place-data in our data
// array, so we unbind the association from Event to Place.
$this->Place->Event->unbindModel(array('belongsTo' =>
array('Place')));
$place = $this->Place->find("Place.id = $id", null, null, 2);
// After the find we did above we do a second find, resulting
in basically the same information, but please
// ignore this for the sake of the example.
// Here we fetch all photosets that belong to this place
(indirectly associated via Event). Assume we do
// want Place-data in our data array, so recursive depth 2
again and no unbind this time.
$photosets = $this->Photoset->findAll("Photoset.event_id =
Event.id AND Event.place_id = $id", null, null, null, null, 2);
}
}
THE PROBLEM:
Eventually the second find (findAll) tries to access the Place field
on an instance of the Event model (this happens in
dboSource::queryAssociation()). This field does not exist as a result
of the first find operation, in which the association from Event to
Place was unbinded.
If the two find operations are switched (first the photosets query,
then the place query), everything is fine. This behavior does not look
very logical. I've studied the source code to comprehend how CakePHP
constructs models and deals with associations internally, but I cannot
really get a grasp on it.
Can anyone shed some light on what is happening here?
Tim
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---