eager-loading

Laravel eager loading with nested relationship

人走茶凉 提交于 2021-02-17 03:10:42
问题 I know this question has been asked but my situation is different. I have Post model with relationship to Comment model defined: /*Post Model*/ public function comments(){ return $this->hasMany('comment'); } and Comment model which each comment belong to one user : / comment model / public function user(){ return $this->belongto('user'); } now I want to query all post and eager load comments (of each post) along with user information who post the comment. anyway to make it work please ? thank

Laravel eager loading with nested relationship

眉间皱痕 提交于 2021-02-17 03:09:44
问题 I know this question has been asked but my situation is different. I have Post model with relationship to Comment model defined: /*Post Model*/ public function comments(){ return $this->hasMany('comment'); } and Comment model which each comment belong to one user : / comment model / public function user(){ return $this->belongto('user'); } now I want to query all post and eager load comments (of each post) along with user information who post the comment. anyway to make it work please ? thank

Laravel eager loading with nested relationship

别等时光非礼了梦想. 提交于 2021-02-17 03:08:03
问题 I know this question has been asked but my situation is different. I have Post model with relationship to Comment model defined: /*Post Model*/ public function comments(){ return $this->hasMany('comment'); } and Comment model which each comment belong to one user : / comment model / public function user(){ return $this->belongto('user'); } now I want to query all post and eager load comments (of each post) along with user information who post the comment. anyway to make it work please ? thank

Hibernate native SQL query - how to get distinct root entities with eagerly initialized one-to-many association

流过昼夜 提交于 2021-02-11 14:27:04
问题 I have two entities Dept and Emp (real case changed and minimized). There is 1:n association between them, i.e. properties Dept.empList and Emp.dept exist with respective annotations. I want to get List<Dept> whose elements are distinct and have collection empList eagerly initialized, using native SQL query. session.createSQLQuery("select {d.*}, {e.*} from dept d join emp e on d.id = e.dept_id") .addEntity("d", Dept.class) .addJoin("e", "d.empList") //.setResultTransformer(Criteria.DISTINCT

Laravel eager load function limit

ぃ、小莉子 提交于 2021-01-16 04:23:19
问题 I have a working function, however, I'd like to limit the number of treatments, per consultant, that are returned. Working Example: Clinic::where('user_id', Auth::id()) ->with('consultants.specialism', 'consultants.treatments') ->first(); Proposed (but not working) example: Clinic::where('user_id', Auth::id()) ->with('consultants.specialism') ->with(['consultants.treatments' => function ($query) { $query->take(3); }]) ->first(); Unfortunately, the take or limit function, limits it to the

Laravel eager load function limit

别说谁变了你拦得住时间么 提交于 2021-01-16 04:21:54
问题 I have a working function, however, I'd like to limit the number of treatments, per consultant, that are returned. Working Example: Clinic::where('user_id', Auth::id()) ->with('consultants.specialism', 'consultants.treatments') ->first(); Proposed (but not working) example: Clinic::where('user_id', Auth::id()) ->with('consultants.specialism') ->with(['consultants.treatments' => function ($query) { $query->take(3); }]) ->first(); Unfortunately, the take or limit function, limits it to the

Laravel eager load function limit

只愿长相守 提交于 2021-01-16 04:21:07
问题 I have a working function, however, I'd like to limit the number of treatments, per consultant, that are returned. Working Example: Clinic::where('user_id', Auth::id()) ->with('consultants.specialism', 'consultants.treatments') ->first(); Proposed (but not working) example: Clinic::where('user_id', Auth::id()) ->with('consultants.specialism') ->with(['consultants.treatments' => function ($query) { $query->take(3); }]) ->first(); Unfortunately, the take or limit function, limits it to the