Tuesday, October 30, 2012

Re: Paginate with associated model conditions

I am also facing the same issue.
The pagination works well if I unbind all the models and if I bind some models then even find query is working fine but not with 'count(*)' query in pagination. Kindly help.


On Monday, July 9, 2012 12:14:25 AM UTC+5:30, Michael wrote:
No on knows how to solve this issue? I have a few very complicated work arounds, but every time I end up implementing such work arounds, it always comes back to the fact that I was doing it wrong originally. 

~Michael

On Fri, Jul 6, 2012 at 12:09 AM, Michael Gaiser <mjga...@gmail.com> wrote:
So I am having some issues getting Paginate to recognize its associated models when handling its conditions. Some events have a location_id, but others (like the feeding event) have their location id specified in the associated model. From the Events Index page I want to do a search for all events that have the location_id = 87. Heres my setup.

Event hasMany Feeding (EventsFeeding table)

$conditions['OR'] = array(
'Event.location_id'=>87,
'Feeding.location_id'=>87,
);


$this->paginate = array(
'limit'=>$count,
'contain' =>array(
'Feeding'=>array('id', 'event_id', 'location_id'),
),
'fields'=>array('id', 'event_type_id', 'location_id', 'start_date', 'end_date', 'created', 'modified'),
'order'=>array('Event.start_date ASC')
);

$events = $this->paginate($conditions);


This is the error I get:
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Feeding.event_id' in 'field list'


I have looked around, some solutions I have found try to make use of a fake hasOne bind, others try to setup a virtual field others play around with the 'joins' array. I have tried all of these but cannot seem to get them to work. Any help would be greatly appreciated.

~Michael

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

No comments: