Tuesday, December 29, 2009

adding hasMany association couse find() not to work well

OK, i am little bit lost...

i am pretty new to php, and i am trying to use cakePHP for my web-
site.
my db is composed of two tables:

- users with user_id, name columns
- copies with copy_id, copy_name, user_id (as foreign key to users)
columns.

and i have the matching cakePHP elements:

- User and Copy as a model
- UserController as controller
- i dont use a view since i just sending the json from the
controller.

i have added hasMany relation between the user model and the copy
model see below.

var $hasMany = array('Copy' => array('className'=>'Friendship',
'foreignKey' =>user_id'));

with out the association Every find() query on the users table works
well, but after adding the hasMany to the model the same find()
queries on the users stop working (print_r does show anything), and
every find() query i am applying on the Copy model

$copy= $this->User->Copy->find('all', array('condition'=>array
('Copy.user_id'=>'2')));
ignores the condition part and just return the whole data base.

how can i debug the code execution? when i am adding the debug($var)
nothing happens.

sorry for the length, it is just i am a little bit lost with this..


i have a User model, and a users_controler, that correspond to the
users table in my DB.
i also have a Friendship model, and a friendship


when i am trying to use the find() function every thing works well,
but when i am adding to the model a hasMany association suddenly the
results are

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: