Alex
Alex

Reputation: 6475

Cakephp - Paginating data from another model

I am trying to do pagination from the accommodation controller but with data from the MemberWall model.

here is the code

Accommodation

$data = $this->Accommodation->Member->MemberWall->paginate('MemberWall');

MemberWall

var $paginate = array(
 'limit' => 4,
 'order' => array(
   'MemberWall.created' => 'asc'
 )
); 

I get this error

SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use nea....   Query: paginate 

Thanks, Alex

Upvotes: 4

Views: 9484

Answers (4)

Leo
Leo

Reputation: 6571

  1. The MemberWall $paginate array (your second snippet) looks like it's defined in member_walls_controller.php It will not be accessible from accommodations_controller.php

  2. $this->Accommodation->Member->MemberWall->paginate('MemberWall'); is calling a method on the MemberWall model. paginate() is a controller method.

  3. Read Custom-Query-Pagination, particularly the last section.

  4. I'm not sure that you can paginate that far down a relationship and it indicates to me that you probably need to rethink your datamodel and logic.

  5. The 1.2 manual is better written on this topic.

Upvotes: -2

Alex K
Alex K

Reputation: 15838

Here is the REAL answer.

$data = $this->paginate($this->Accommodation->Member->MemberWall);

I had trouble finding this in the docs too. You can actually pass a model object into the paginate method.

Upvotes: 18

TheTambu
TheTambu

Reputation: 131

I've tried and it works in both ways:

$this->paginate('MemberWall');

$this->paginate($this->Accommodation->Member->MemberWall);

In my code I use something like;

$this->loadModel('MemberWall');

$this->paginate = array(.....);

$data = $this->paginate('MemberWall');

Upvotes: 8

dogmatic69
dogmatic69

Reputation: 7575

$this->paginate('MemberWall'); iirc is the way it works

Upvotes: 0

Related Questions