self::find()->with('book.lastItem')->where("uid = {$uid}")->orderBy('id desc')->asArray()->all();
public function getBook() {
return $this->hasOne(Book::class, ['id' => 'book_id']);
}
public function getLatItem(){
return $this->hasOne(BookItem::class, ['book_id' => 'id'])->orderBy('id desc');
}
app\models\Book has no relation named "lastItem".
with 不支持我这种写法还是?
1
2kCS5c0b0ITXE5k2 2020-01-05 16:11:58 +08:00
用 with 不如自己 join 或者自己查再拼起来
|
2
fangwenxue OP @emeab
找到问题了,getLatItem 方法名错了 |
3
zhzhwcn 2020-01-05 22:44:22 +08:00
`book.lastItem` VS `getLatItem`
|