-
Notifications
You must be signed in to change notification settings - Fork 1.5k
query condition on "with" relation not work #2265
Unanswered
sepisoltani
asked this question in
Q&A
-
I have a Order Model which has belongsTo relation to Factor model
use Jenssegers\Mongodb\Eloquent\Model; class Order extends Model { public function factor() { return $this->belongsTo(Factor::class, 'factor_id'); } }
I want to load orders which only their factor status is 'payed'.
I run this query but it loads all orders.
$res = Order::with(['factor' => function ($query) { $query->where('status', '=',"payed"); }])->get()
if I change the "with" , to "whereHas" it works.
why "with" doesn't work ?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
With-> only relations records will be filtered. WhereHas will filter main table's record.
Beta Was this translation helpful? Give feedback.
All reactions
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment