can you please post your database structure that can easily find out what
you actually want????
On Sunday, July 15, 2012 7:30:05 AM UTC+5:30, Michael wrote:
>
> I am trying to get my mind around using joins in my finds to gain the
> ability to use associated models in my conditions. I run into a lot of
> with HABTM relationships so instead I just use join tables with
> hasMany/belongsTo relationships. The following works without the 'joins'
> array but when its added, I get errors about "Feedings.event_id" being an
> unknown column. The end goal is to only pull up the Feedings that have an
> Event that matches the given conditions. Without using the 'joins' array,
> it returns all Feedings records from the database with an empty array
> assigned to each Event unless of course it met the conditions where it
> would then fill in that Events info. Any help would be greatly appreciated.
>
>
> $domain = $this->Feeding->Location->Domains->Domain->find('first', array(
> 'joins'=>array(
> array(
> 'table'=>'events',
> 'alias' => 'Event',
> 'type' => 'inner',
> 'conditions' => array(
> 'Event.id = Feedings.event_id'
> ),
> ),
> ),
>
> 'contain' => array(
> 'Locations'=>array('id', 'additive',
> 'Location'=> array('name','type_id',
> 'conditions'=>array('type_id'=>3),
> 'Population'=>array('amount','date'),
> 'ChildLocation'=>array('id', 'name', 'type_id',
> 'Population'=>array('id', 'amount',
> 'conditions'=>array(
> 'OR'=>array('Population.chronicle_id'=>array(0, $chronicleId)),
> 'AND'=>array('Population.date <='=>$dbTimeEnd),
> ),
> ),
> 'Feedings'=>array('id', 'event_id', 'location_id', 'amount',
> 'Event'=>array('id', 'event_type_id', 'chronicle_id', 'start_date',
> 'conditions'=>array(
> 'Event.chronicle_id'=>$chronicleId,
> 'Event.start_date >='=>$dbTimeStart,
> 'Event.start_date <='=>$dbTimeEnd),
> ),
> ),
> 'order'=>array('ChildLocation.name ASC'),
> ),
> ),
> ),
> 'Character'=>array('id', 'name',
> 'conditions'=>array('Character.chronicle_id'=>$chronicleId,
> 'Character.in_character'=>false),
> ),
> 'Ratios'=>array(
> 'fields'=>array('id', 'ratio', 'date'),
> 'conditions'=>array('Ratios.date <='=>$dbTimeEnd),
> 'order'=>array('Ratios.date'=>'DESC'),
> 'limit'=>1,
> ),
> ),
> 'fields' => array('id', 'name', 'type_id'),
> 'conditions'=>array('Domain.id' => $domainId, 'Domain.type_id'=>6,
> 'Domain.confirmed_id !='=>null),
> )
> );
>
--
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