Hello everybody,
I try to use a containable search in a CakePHP legacy project using Cake
1.2. I have often uses containable, but never togeterh with aliases. So
no idea if that might be the poblem ore something else.
The model relations are as follows:
Group__
hasMany Members alias Users
belongsTo
|__ GroupOwner alias User
|__ LastPost alias ForumPost
|___belongsTo
|__ PostAuthor alias User
As you can see we use model aliases.
I have the following containment array:
$containment = array(
'GroupOwner' =array(
'fields'=array('GroupOwner.nickname',
'GroupOwner.id')
),
'LastPost' =array(
'fields'=array(
'LastPost.user_id',
'LastPost.created'),
'PostAuthor' =array(
'fields' =array(
'PostAuthor.id',
'PostAuthor.firstname',
'PostAuthor.nickname',
'PostAuthor.lastname')
)
)
);
The strange behaviour is that I get all model data on the second level
e.g. all my GroupMembers which I don't want, but not my PostAuthor which
I want.
If I add a field condition to my find e.g.:
$groups = $this-Group-find('all', array('contain' =$containment,
'fields' =array('GroupOwner.id'), 'limit' =2));
my result looks like following:
GroupOwner (Array, 5 elements)
id (String, 2 characters ) 14
nickname (String, 11 characters ) Helfenstein
avatar (Array, 4 elements)
is_online (Integer) 0
name (String, 12 characters ) Helfenstein
LastPost (Array, 3 elements)
user_id (String, 6 characters ) 878781
created (String, 10 characters ) 1237332851
id (String, 10 characters ) 1009713631
GroupCategory (Array, 0 elements)
Member (Array, 0 elements)
Tags (Array, 0 elements)
so Members are still there, though luckily empty, but still no PostAuthor. My
complete Information from the "Group" model is missing, too
*sigh*
Has anybody an idea what might be the problem?
Of course var $actsAs = array('Containable'); is set in the app_model.php
I find this a very strange behaviour (no pun intended).
Thanks in advance for any help!
Anja
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php