Joining multiple tables

Joining multiple tables

alan3222hkalan3222hk Posts: 2Questions: 1Answers: 0

Hi,

I have a table with this relationship:

one order -> one to many products -> one to one image

I can link the order and products with:

Editor::inst($db, 'orders')
  ->field(
    Field::inst('orders.id'),
    Field::inst('orders.name'),
    Field::inst('orders.order_date')
  )
  ->join(
    Mjoin::inst('products')
      ->link('orders.id', 'orders_products.order_id')
      ->link('products.id', 'orders_products.product_id')
      ->field(
        Field::inst('id'),
        Field::inst('products', 'title'),
        Field::inst('image_id')
        )
    )
  );

How can I link the products.image_id to table 'images'?

thx!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 50,737Questions: 1Answers: 7,581 Site admin
    Answer ✓

    Hi,

    Unfortunately the Mjoin does not have a left join method itself at the moment. The only way to do this with Editor's PHP libraries would be to create a VIEW based on your products table which does that left join and point the Mjoin at that VIEW (it will select just as if it a regular table).

    Allan

  • alan3222hkalan3222hk Posts: 2Questions: 1Answers: 0

    I see, thx Allan.

Sign In or Register to comment.