我有問題,加入2表,當我執行打擊碼結果代碼正確的,但是從ticket_pin在結果沒有顯示出銷區不合並表字段中加入yii2
$model = Ticket::find()->leftJoin(TicketPin::tableName(), 'ticket.id=ticket_pin.ticket_id and ticket_pin.user_id=1')->all();
[id] => 1
[user_id] => 1
[receiver_user_id] =>
[title] => بسش
[problem] => شسبس
[text] => سشب
[receiver] => 1
[priority] => 1
[status] => 4
[seen] =>
[online] =>
[created_at] => 1490588016
但是當我使用createCommand它的正確顯示的結果,但我需要使用ActiveRecord
Yii::$app->db->createCommand('SELECT * FROM ticket LEFT JOIN ticket_pin ON ticket.id=ticket_pin.ticket_id and ticket_pin.user_id=1 order by ticket.id DESC')->queryAll();
[id] =>
[user_id] =>
[reciver_user_id] => 1
[title] => سس
[problem] => afsfsa
[text] => sfaaf
[reciver] =>
[priority] => 1
[status] => 4
[seen] => 0
[online] =>
[{"user_id":2,"name":"\u0645\u062d\u0645\u062f","time":1491378729}]
[created_at] => 1491378692
[ticket_id] =>
[pin] =>
感謝您的soultion我做到了,但有一些問題。 的結果我提其他意見, 但問題是 的foreach($門票$票){ 回聲$ ticket->銷//類似的東西 } 獲得未知屬性:應用程序\型號\票務:: pin –
@ mohammad-zahedimohammad哦..對不起,我錯過了一件事。現在將更新我以前的回答 – Yerke