Reputation: 4351
I am trying to make pretty query result like doctrine, and other ORM
for example with relational table article and article_category.
i want to get query result like this :
Array
(
[0] => Array
(
[id] => 1
[title] => I am article title
[slug] => i-am-article-title
[category] => Array
(
[id] => 1
[name] => Category Name
[slug] => category-name
)
)
[1] => Array
(
[id] => 2
[title] => How to coding
[slug] => how-to-coding
[category] => Array
(
[id] => 4
[name] => Tutorial Area
[slug] => tutorial-area
)
)
)
i know this is basic, but i am want to know for create that result in very simple way.
thanks for all advice
UPDATED.
for to get that result, I am change using eloquent laravel framework.. . :)
Upvotes: 0
Views: 347
Reputation: 8995
No, you can't get this information in this way directly from your database if you are using a Relational Database like MySQL or PostgreSQL
You can get the effect you wish in two queries and insert the subquery array to your result array, or you can have a different table for your categories and do a JOIN with SQL.
As a note, other database systems return just what you asked, consider switching to MongoDB (a No-SQL solution) it returns an object just like you wished
Upvotes: 1