fangwenxue
V2EX  ›  问与答

yii2 with 问题

  •  
  •   fangwenxue · Jan 5, 2020 · 2129 views
    This topic created in 2340 days ago, the information mentioned may be changed or developed.

    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 replies    2020-01-05 22:44:22 +08:00
    2kCS5c0b0ITXE5k2
        1
    2kCS5c0b0ITXE5k2  
       Jan 5, 2020
    用 with 不如自己 join 或者自己查再拼起来
    fangwenxue
        2
    fangwenxue  
    OP
       Jan 5, 2020
    @emeab
    找到问题了,getLatItem 方法名错了
    zhzhwcn
        3
    zhzhwcn  
       Jan 5, 2020
    `book.lastItem` VS `getLatItem`
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3258 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 14:10 · PVG 22:10 · LAX 07:10 · JFK 10:10
    ♥ Do have faith in what you're doing.