I 다음 SQL을 가지고SQL 가입 그룹 항목
SELECT articles.id, articles.title, tags.name AS tags
FROM articles
LEFT JOIN article_tag_association ON articles.id = article_tag_association.article_id
LEFT JOIN tags ON tags.id = article_tag_association.tag_id
가 제한
예컨대 놨어요 물품이 갖는 각 태그에 대한 행을 생성 제외이 OK 작동
[
"0" => ["id" => "1", "title" => "test", "tags" => "tag1"],
"1" => ["id" => "1", "title" => "test", "tags" => "tag2"],
"2" => ["id" => "2", "title" => "test2", "tags" => "tag1"],
]
(만 2 개 기사하지만 세 행)
는 태그의 배열과 각 기사를 반환 할 수있는 방법이있다? 같은
뭔가 :
[
"0" => ["id" => "1", "title" => "test", "tags" => ["tag1", "tag2"]],
"1" => ["id" => "2", "title" => "test2", "tags" => ["tag1"]],
]
당신은 당신의 테이블 창조를 게시 할 수 있냐? 문자열 형식의 "배열"을 생성하는 것이 더 쉬울 수도 있습니다 –