得到不明财产Yii 2加入

时间:2016-09-16 04:07:49

标签: php yii2

您好我Getting unknown property: app\models\ActiveCurriculum::period period列位于schead

我已使用此代码加入表格。

ActiveCurriculum::find()
                                ->select('scstock.*')
                                ->joinWith('schead')
                                ->where(['schead.TrNo' => $TrNo])
                                ->one();

你能帮助我吗?

编辑1(已修复)

SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误;查看与您的MariaDB服务器版本相对应的手册,以便在#schead附近使用正确的语法。TrNo =' 29005''在第1行 正在执行的SQL是:SELECT scstock。* FROM scstock LEFT JOIN schead WHERE scheadTrNo =' 29005'

enter image description here

编辑2:我设法修复了它,但我又遇到了一个新错误

"必须将join子句指定为连接类型,连接表和可选的连接条件数组。"

ActiveCurriculum::find()
                                ->select(`scstock.*`)
                                ->leftJoin(`schead`)
                                ->where([`schead.TrNo` => $TrNo])
                                ->one();

1 个答案:

答案 0 :(得分:0)

 ActiveCurriculum::find()->select('scstock.*')
                         ->joinWith('schead')
                         ->where(['schead.TrNo' => $TrNo])
                         ->one();
// here joinWith('schead') means `schead` is name of the class 
ActiveCurriculum::find()->select('scstock.*')
                         ->joinLeft('schead','schead.scheadid=scstock.scheadid') // scheadid is the common field between two fields
                         ->where(['schead.TrNo' => $TrNo])
                         ->one();