Skip to content
This repository was archived by the owner on Aug 27, 2024. It is now read-only.

How to get data include data of related tables #3

Open
sariluong opened this issue Jul 28, 2018 · 0 comments
Open

How to get data include data of related tables #3

sariluong opened this issue Jul 28, 2018 · 0 comments

Comments

@sariluong
Copy link

When I get data of a parent table, I also need to get data of children with parentID. Currently, I do this action by two statements and store data in two arrays. Disvantage of this thing is when I use foreach(parent), I must call getNameByID to get the name of parentID. And foreach(children) also. Then assign name back to parent.

Question: Can we get data by one statement, and data of children will be stored as associated array in parent?
Like thtis:

$db->rows("SELECT * FROM ParentTable", [
    'assocaited' => [ 'ParentDetailTable', 'ChildrenTable']
]);

And data will be returned:

parent => [
    id => '1',
    createdAt => 'Jul, 28 2018',
    'detail' => [name, color, university...],
    children => [
        child1 => [
        ],
        child2 => [
        ],
    ]
]


RDBMS is relation of tables. So I think we usually get this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant