2

So my models work like this:

  • User has one Investor
  • Investor has many Investments
  • Investments has many Bids
  • Bids belogs to ObjectInAuction
  • ObjectInAuction has many Bids

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?

Warren Sergent
  • 2,542
  • 4
  • 36
  • 42
Alejandro
  • 1,159
  • 3
  • 16
  • 30

0 Answers0