inner join in cakephp 2.0?

I know it is a little bit lazy to ask this question here because basically I just need to read the documentation for me to know the answer. But actually I don't have that much of time, and I'm still a beginner.

I want to produce this kind of query in cakephp:

SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
FROM Persons
INNER JOIN Orders
ON Persons.P_Id=Orders.P_Id
ORDER BY Persons.LastName

but the question is I'm a little bit confused because as you can see you will select values from 2 different tables. So my guess is, I need to create two models for each and controllers. is it a little bit of a hassle?

Upvotes: 0

Views: 3057

Answers (1)

Ryan Gibbons
Ryan Gibbons

Reputation: 3611

What you are wanting to do is is the basic Model Associations provided by CakePHP. http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html

So yes, you will need to create Models for each, probably have an association so a Person has many orders.

Further more, with MVC architecture, you will normally have one model per table in your database. Your controller will handle the communication between the Model and the Views. So if don't need dedicated views for a model, then you might not need Controllers for them.

I really suggest you go through the Book for CakePHP and do the Blog demo they provide and really try to under the concepts presented for MVC Architecture.

Upvotes: 1

Related Questions