Skip to main content

cakephp CakePHP find method with joinJOIN

Hi i,

I need to do the following query using the cakephp findCakePHP find method:

SELECT *   FROM `messages`   INNER JOIN users ON messages.from = users.id   WHERE messages.to=4to = 4 ORDER BY messages.datetime DESC 

Basically I have:

messages table with a Message model

users table with User model

  • messages table with a Message model
  • users table with User model

and want to retrieve information from both tables in one query. The users.idusers.id field is the same as the messages.frommessages.from field, so thatsthat's what the join is on.

I am doing it in my messages controllerMessagesController so it would need to be something like:

$this->Message->find(); 

Thanks

cakephp find with join

Hi i need to do the following query using the cakephp find method:

SELECT * FROM `messages` INNER JOIN users ON messages.from = users.id WHERE messages.to=4 ORDER BY messages.datetime DESC 

Basically I have:

messages table with a Message model

users table with User model

and want to retrieve information from both tables in one query. The users.id field is the same as the messages.from field so thats what the join is on.

I am doing it in my messages controller so it would need to be something like:

$this->Message->find(); 

Thanks

CakePHP find method with JOIN

Hi,

I need to do the following query using the CakePHP find method:

SELECT *  FROM `messages`  INNER JOIN users ON messages.from = users.id  WHERE messages.to = 4 ORDER BY messages.datetime DESC 

Basically I have:

  • messages table with a Message model
  • users table with User model

and want to retrieve information from both tables in one query. The users.id field is the same as the messages.from field, so that's what the join is on.

I am doing it in my MessagesController so it would need to be something like:

$this->Message->find(); 

Thanks

Source Link
geoffs3310
  • 14.1k
  • 24
  • 68
  • 86

cakephp find with join

Hi i need to do the following query using the cakephp find method:

SELECT * FROM `messages` INNER JOIN users ON messages.from = users.id WHERE messages.to=4 ORDER BY messages.datetime DESC 

Basically I have:

messages table with a Message model

users table with User model

and want to retrieve information from both tables in one query. The users.id field is the same as the messages.from field so thats what the join is on.

I am doing it in my messages controller so it would need to be something like:

$this->Message->find(); 

Thanks