php - Laravel parent/children relationship on it's own model -
i want vouchers have @ least 1 child, voucher can have multiple voucher children, voucher can have 1 parent.
i set following models , calls, , query generates desired, until part: 'vouchers'.'parent_id' = 'vouchers'.'id'
wanted functionality:
$vouchers = voucher::has('children')->get();
or
$vouchers = voucher::has('parent')->get();
resulted query
select * `vouchers` `vouchers`.`deleted_at` null , (select count(*) `vouchers` `vouchers`.`deleted_at` null , `vouchers`.`parent_id` = `vouchers`.`id` , `vouchers`.`deleted_at` null ) >= 1
models:
class voucher extends basemodel { public function parent() { return $this->belongsto('voucher', 'parent_id'); // return $this->belongsto('voucher', 'parent_id', 'id'); <- attempted din't work } public function children() { return $this->hasmany('voucher', 'parent_id'); } }
this issue has been reported , fixed in 5.0 https://github.com/laravel/framework/pull/8193
unfortunately there no port version 4.
however if want apply fix can see list of modifications here : https://github.com/laravel/framework/pull/8193/files
be carefull, modifying framework's code base @ risk there no more bug fixes on laravel 4.x version, security fixes few more month.
Comments
Post a Comment