So my models work like this:
User
has oneInvestor
Investor
has manyInvestments
Investments
has manyBids
Bids
belogs toObjectInAuction
ObjectInAuction
has manyBids
I need to build a function in ObjectInAuction
that returns all the ObjectInAuction
entities that have been invested by the User
with some $user_id
.
This is what I have in ObjectsInAuctionTable.php
:
public function getAuctionObjectsInvestedBy($user_id)
{
$query = $this->find();
$query->contain([
'Bids.Investments.Investors' => function ($q) use ($user_id) {
return $q->where(['Investors.user_id' => $user_id]);
}
]);
}
$invoices = $query->all();
The problem is that this is returning all invoices in the database, every time. How can I make this work?