Laravel 4 - Can't retrieve data in a one-to-many relationship

前端 未结 5 1354
故里飘歌
故里飘歌 2021-01-21 18:45

I have a Quote model:

class Quote extends Eloquent {

    public function quote_lines() {
        return $this->hasMany(\'QuoteLine\');
    }    

}
         


        
5条回答
  •  暖寄归人
    2021-01-21 19:15

    I have the exact same problem with Laravel 4.1, and the solution suggested by this comment solved it for me.

    Putting an underscore anywhere in the function name causes it to return null:

    public function quo_telines() {
        return $this->hasMany('QuoteLine');
    }
    

    Removing the underscore resolves the issue. Apparently, Eloquent doesn't like to have an underscore in the function name.

    However, note that the function name must not match any of the schema's column names, or you'll get other issues.

提交回复
热议问题