Hi All - I’m facing an issue in fetching data using relationship. Below is the detail:
I’m having two tables. First is “item_master” and Second is “inventory” table. Since both are having MANY_MANY relationship, so we are having another table named “inventory_items”. “inventory_items” table is having only two fields: item_id, inventory_id.
Below is the relationship detail in ItemMaster Model:
Above code is returning me all the items with the required inventory. And if an item does not belong to that inventory than still it returns that Item but without inventory. I just need that only those Items should return which belong to a particular inventory.
But he wants to use "INNER JOIN" and that should also work.
to Ravi: try to also add ‘together’=>true to $inventory_condition. This is a HAS_MAN relation so by default YII AR is not loading it with same query, but in second one and merges results with primary table results.