Hello everyone
I'm having a problem with the containable-Behavior.
I have this Data Model:
Article belongsTo Publication
Publication hasMany AuthorsPublication
AuthorsPublication belongsTo Publication, Author
Author hasMany AuthorsPublication
Now I want to get all articles and their related authors.
Without conditions it works like a charm, but when I want to filter
the output by for example a certain author
(i.e. find should return only the Articles that are written by Author
X)
I tried 2 different ways of achieving this, but both failed with
different results:
$data = $this->Article->find(
'all',
array(
'contain' => array(
'Publication' => array(
'AuthorsPublication' => array(
'Author'
)
)
),
'limit' => 5,
'conditions' => array(
'AuthorsPublication.author_id' => 4
)
)
);
This one produces an error stating "SQL Error: 1054: Unknown column
'AuthorsPublication.author_id' in 'where clause'" (which is somehow
logical, considering the way the SQL-Queries are made)
The other way is:
$data = $this->Article->find(
'all',
array(
'contain' => array(
'Publication' => array(
'AuthorsPublication' => array(
'conditions' => array(
'AuthorsPublication.author_id' => 4
),
'Author'
)
)
),
'limit' => 5
)
);
This time Cake returns the first 5 Articles with the corresponding
Publication-Data, but the corresponding AuthorsPublication-Data is
only present where AuthorsPublication.author_id is 4
(so one could say that the filtering entered a level too low, as I
wanted to skip the results without author_id completely)
Is there any way to achieve the results I want without correcting the
Containable-Behavior (I say correcting, because I have seen similar
bug reports on the bugtracker), or do I have to revert to the "old"
unbindModel thingy?
I appreciate your answers :)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to
[hidden email]
To unsubscribe from this group, send email to
[hidden email]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en-~----------~----~----~----~------~----~------~--~---