Re: Using belongsTo and hasMany relationships: Is it possible to access tables through a chain of relationships?

2009-08-31 Thread delocalizer
now I understand, you want associated user animal info for all specified Userpages... so as I suggested before, do the find on Userpage model... but use contain to provide the associated stuff: $pages = $this-Userpage-find('all',array( 'conditions'=array( 'or'=array(

Re: Using belongsTo and hasMany relationships: Is it possible to access tables through a chain of relationships?

2009-08-31 Thread Sarah
Yay! The query works! :) Thank you! I really appreciate your patience. :) Thanks for your time and knowledge! ~Sarah On Aug 30, 11:07 pm, delocalizer conrad.leon...@hotmail.com wrote: now I understand, you want associated user animal info for all specified Userpages... so as I

Re: Using belongsTo and hasMany relationships: Is it possible to access tables through a chain of relationships?

2009-08-30 Thread delocalizer
Ah I hadn't realised you just wanted Userpages - in which case why not call find on Userpage? If you're in Users controller: $pages = $this-User-Userpage-find('all',array( 'conditions'=array( 'or'=array( 'approved'=1, 'and'=array(

Re: Using belongsTo and hasMany relationships: Is it possible to access tables through a chain of relationships?

2009-08-30 Thread Sarah
I'm performing this in the Userpages controller. I was calling find on Users because I need information on the user's animal. User hasMany Userpages User belongsTo Animal The foreign keys are set up appropriately. I need to get a list of all userpages in which: (Userpages.approved = 1) OR

Re: Using belongsTo and hasMany relationships: Is it possible to access tables through a chain of relationships?

2009-08-30 Thread delocalizer
ok... but I'm still not sure exactly what your intent is. When you say you need information on THE user's animal - do you mean there is a particular user that you are trying to get information on, like the current requesting user? $id is a unique value in your method (ie. not a loop iterator or

Re: Using belongsTo and hasMany relationships: Is it possible to access tables through a chain of relationships?

2009-08-30 Thread Sarah
I would like the results from the query to include all userpages that either have an approved value of 1 or belong to the current user (whose id is stored in the $id var) and have an approved value of -1. Basically I want a list of all userpages that are approved for public viewing or that are

Re: Using belongsTo and hasMany relationships: Is it possible to access tables through a chain of relationships?

2009-08-29 Thread delocalizer
Hi Sarah, If you have a reasonably complicated find query with associated models and conditions, the core 'Containable' behaviour is very handy: http://book.cakephp.org/view/474/Containable so in your AppModel put this (and all your models will have access to the behaviour): var $actsAs =

Re: Using belongsTo and hasMany relationships: Is it possible to access tables through a chain of relationships?

2009-08-29 Thread Sarah
Wow, this was very cool. Thank you for the advice. I realized I had forgotten a condition. So this is where I am now: $array = $this-User-find('all', array( 'fields'=array('id', 'animal_id'), 'order'=array('User.id'='asc'),

Re: Using belongsTo and hasMany relationships: Is it possible to access tables through a chain of relationships?

2009-08-28 Thread Sarah
$conditions = array('or' = array( 'Userpage.approved' = 1, 'User.id' = $id ) ); $order = array('User.id ASC', 'Userpage.id DESC'); $array = $this-User-find($conditions, array('id, 'Userpage.id', 'User.animal_id', 'Animal.frontfilename'), $order); I get the following errors:

Re: Using belongsTo and hasMany relationships: Is it possible to access tables through a chain of relationships?

2009-08-28 Thread WebbedIT
Looks like you very nearly had it. Just got your find syntax slightly wrong, try: $array = $this-User-find('all', array( 'fields'=array('id, 'Userpage.id', 'User.animal_id', 'Animal.frontfilename'), 'conditions'=$conditions, 'order'=$order ); Then go have a look at the cookbook and study

Re: Using belongsTo and hasMany relationships: Is it possible to access tables through a chain of relationships?

2009-08-28 Thread Sarah
I fixed my syntax, $conditions = array('or' = array( 'Userpage.approved' = 1, 'User.id' = $id) ); $order = array('User.id ASC', 'Userpage.id DESC'); $array = $this-User-find('all', array('fields'=array('id', 'Userpage.id', 'User.animal_id', 'Animal.frontfilename'), 'conditions'=$conditions,

Using belongsTo and hasMany relationships: Is it possible to access tables through a chain of relationships?

2009-08-27 Thread Sarah
This is my setup: A 'user' hasMany 'userpage's. A 'user' belongsTo an 'animal'. I would like to be able to display user information as well as some information about the user's animal on a userpage view. I perform a find query to get the userpage id, user_id, animal_id. Is there a way to

Re: Using belongsTo and hasMany relationships: Is it possible to access tables through a chain of relationships?

2009-08-27 Thread Sarah
Ah, that worked. :) Thank you! On Aug 27, 3:19 pm, delocalizer conrad.leon...@hotmail.com wrote: Hi Sarah; If your relationships are set up correctly and you have recursive -1, the usual 'find' method on User model should be returning the parent 'Animal' anyway - what do you see if you

Re: Using belongsTo and hasMany relationships: Is it possible to access tables through a chain of relationships?

2009-08-27 Thread Sarah
The only problem I am having with this is that userpages are then received like this: [Userpage] = Array ( [0] = Array ( [id] = 2 [filename] = helloworld.html [type] = text/html

Re: Using belongsTo and hasMany relationships: Is it possible to access tables through a chain of relationships?

2009-08-27 Thread delocalizer
Hi Sarah; If your relationships are set up correctly and you have recursive -1, the usual 'find' method on User model should be returning the parent 'Animal' anyway - what do you see if you put this in one of your user controller functions: $example = $this-User-find('first'); debug($example); ?

Re: Using belongsTo and hasMany relationships: Is it possible to access tables through a chain of relationships?

2009-08-27 Thread Sarah
To clarify, I get the error message: Warning (512): SQL Error: 1054: Unknown column 'Userpage.id' in 'field list' [CORE/cake/libs/model/datasources/dbo_source.php, line 525] When I try to get select the Userpage.id field. On Aug 27, 3:19 pm, delocalizer conrad.leon...@hotmail.com wrote: Hi

Re: Using belongsTo and hasMany relationships: Is it possible to access tables through a chain of relationships?

2009-08-27 Thread delocalizer
Hi Sarah; I'm not sure what you are asking. User hasmany Userpages, so Userpage array will contain all the Userpages belonging to User. $example = $this-User-find('first'); foreach($example['Userpage'] as $key=$value){ debug($value['id']); } On Aug 28, 9:18 am, Sarah