php
1public static function staffIds_find($id){ 2 $query = DB::query('SELECT projects.id as id, projects.project_id as project_id 3 , projects.name as name 4 , projects.date1 as date1 5 , clients.company as client 6 FROM projects left join clients on projects.client_id = clients.id WHERE 7 JSON_CONTAINS(staff_ids,:id,"$.staff1") OR 8 JSON_CONTAINS(staff_ids,:id,"$.staff2") OR 9 JSON_CONTAINS(staff_ids,:id,"$.staff3") OR JSON_CONTAINS(staff_ids,:id,"$.staff4") OR 10 JSON_CONTAINS(staff_ids,:id,"$.staff5")')->bind('id', $id)->execute(); 11 return $query; 12 } 13
fuelphpで上記のようなsqlを書き結果が下記になるのですが、
ormを使って取得した場合は「client」の中に「clients」テーブルが配列で入ります。
このようなsqlを書くにはどのようなsqlを書けば良いんでしょうか?
php
1//foreachした際の結果 2Array ( [id] => 2 [project_id] => test1123655 [name] => テスト [date1] => [client] => テスト会社 ) 3 4//ormを使ってリレーションした際 5Array ( [id] => 2 [project_id] => test1123655 [staff_ids] => {"staff1": "", "staff2": "", "staff3": "1", "staff4": "", "staff5": "", "staff6": "", "staff7": "", "staff8": ""} [client_id] => 2 [name] => テスト [date1] => [fields] => {"file1":"","file2":"","file3":"","file4":"","file5":""} [created_at] => 1652364334 [updated_at] => 1652501263 [client] => Array ( [id] => 2 [client_id] => test225 [company] => テスト会社 [name] => [email] => test@gmail.com [address] => [date1] => 30 [date2] => 30 [fields] => {"zip":"","address":"","department":"","tel":"","fax":"","email":"test@gmail.com","title":"","remarks":""} [created_at] => 1652107674 [updated_at] => 1652501290 ) )
あなたの回答
tips
プレビュー