Re: HABTM and Pagination

2010-08-22 Thread sanedevil
Hi Walt,

Few days back I had a similar issue. I tried everything. In the end,
there was just one thing that worked for me - Custom Joins.
http://book.cakephp.org/complete/1000/Models#Joining-tables-1047

HTH

On Aug 21, 2:16 am, Walt walt.norb...@gmail.com wrote:
 Hello Everone,

 Perhaps I'm daft. I find folks that have similar issues, but none seem
 to be as direct as I need it to be.

 I'm trying to write a simple search, but the HABTM relationship I have
 seems to be getting in the way.

 I have three models in the search: Person, Role, and Institution.

 Person HABTM Role
 Person Belongs to Institution

 In my controller, I've built my conditions like this:

  $this-Person-recursive = 2;

  $contain = array(
    'Institution',
    'Role'
  );

  $this-paginate = array(
    'limit' = 10,
    'order' = array('Person.username' = 'asc'),
  );

  $conditions = array(
    'Person.username LIKE' = '%'.$username.'%',
    'Person.department LIKE' = '%'.$department.'%',
    'Person.email LIKE' = '%'.$email.'%',
    'Institution.id' = $institutionId,
    'Role.id' = $roleId,
  );

  $this-set('people', $this-paginate('Person',$conditions));

 The above code works if I omit the Role criteria. Since I would only
 like to search for people with certain roles, I really do need that
 extra bit. With the Role criteria, I recieve the following error,
 which seems consistent with something hairy going on with the HABTM I
 have set up:

 Unknown column 'Role.id' in 'where clause'

 Could someone point me to a decent solution. It seems like this should
 have been worked out before.

 I sincerely appreciate any help you can offer.

 Thanks,
 Walt

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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: HABTM and Pagination

2010-08-22 Thread Walt
I like that solution. I'll try it out. Thanks for the ref to the
cookbook. I will write back with my solution if this works!

Walt


On Aug 22, 1:54 am, sanedevil sanede...@gmail.com wrote:
 Hi Walt,

 Few days back I had a similar issue. I tried everything. In the end,
 there was just one thing that worked for me - Custom 
 Joins.http://book.cakephp.org/complete/1000/Models#Joining-tables-1047

 HTH

 On Aug 21, 2:16 am, Walt walt.norb...@gmail.com wrote:



  Hello Everone,

  Perhaps I'm daft. I find folks that have similar issues, but none seem
  to be as direct as I need it to be.

  I'm trying to write a simple search, but the HABTM relationship I have
  seems to be getting in the way.

  I have three models in the search: Person, Role, and Institution.

  Person HABTM Role
  Person Belongs to Institution

  In my controller, I've built my conditions like this:

   $this-Person-recursive = 2;

   $contain = array(
     'Institution',
     'Role'
   );

   $this-paginate = array(
     'limit' = 10,
     'order' = array('Person.username' = 'asc'),
   );

   $conditions = array(
     'Person.username LIKE' = '%'.$username.'%',
     'Person.department LIKE' = '%'.$department.'%',
     'Person.email LIKE' = '%'.$email.'%',
     'Institution.id' = $institutionId,
     'Role.id' = $roleId,
   );

   $this-set('people', $this-paginate('Person',$conditions));

  The above code works if I omit the Role criteria. Since I would only
  like to search for people with certain roles, I really do need that
  extra bit. With the Role criteria, I recieve the following error,
  which seems consistent with something hairy going on with the HABTM I
  have set up:

  Unknown column 'Role.id' in 'where clause'

  Could someone point me to a decent solution. It seems like this should
  have been worked out before.

  I sincerely appreciate any help you can offer.

  Thanks,
  Walt

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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en