CodeIgniter-MY_Model icon indicating copy to clipboard operation
CodeIgniter-MY_Model copied to clipboard

How to SELECT an article and author in one query

Open iLyadKD opened this issue 8 years ago • 1 comments

Hi, I have two tables: "article" and "user" In the article tab I have a "user_id"

How can I make a single query that allows me to select * from article but also show me the name and lastname of the user from the user table rather than the user_id.

Thank you.

iLyadKD avatar Jul 20 '16 17:07 iLyadKD

To follow most of MY_Model's code standard and recommendation, your tables should be called articles and users. Nevertheless, it is has_one relation in Article_m model and has_many relation in User_m model. Similar example you can find in documentation (related to User and Posts).

Tpojka avatar Jul 22 '16 05:07 Tpojka