V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
fangwenxue
V2EX  ›  问与答

yii2 with 问题

  •  
  •   fangwenxue · 2020-01-05 16:09:16 +08:00 · 1288 次点击
    这是一个创建于 1544 天前的主题,其中的信息可能已经有所发展或是发生改变。

    UserHistory

    self::find()->with('book.lastItem')->where("uid = {$uid}")->orderBy('id desc')->asArray()->all();
    
    
    public function getBook() {
    	return $this->hasOne(Book::class, ['id' => 'book_id']);
    }
    

    Book

    public function getLatItem(){
    	return $this->hasOne(BookItem::class, ['book_id' => 'id'])->orderBy('id desc');
    }
    
    • app\models\Book has no relation named "lastItem".

    • with 不支持我这种写法还是?

    3 条回复    2020-01-05 22:44:22 +08:00
    emeab
        1
    emeab  
       2020-01-05 16:11:58 +08:00
    用 with 不如自己 join 或者自己查再拼起来
    fangwenxue
        2
    fangwenxue  
    OP
       2020-01-05 16:12:40 +08:00
    @emeab
    找到问题了,getLatItem 方法名错了
    zhzhwcn
        3
    zhzhwcn  
       2020-01-05 22:44:22 +08:00
    `book.lastItem` VS `getLatItem`
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1540 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 17:15 · PVG 01:15 · LAX 10:15 · JFK 13:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.