Tables:
Products id|name| Categories id|name_cat|code Pr_cats id|pr_id|cat_id
Here are two models:
class Model_Categorie extends ORM { protected $_table_name = 'categories'; protected $_primary_key = 'code'; protected $_db_group = 'default'; protected $_has_many = array( 'products' => array( 'model' => 'product', 'foreign_key' => 'cat_id', 'through' => 'pr_cats', 'far_key' => 'pr_id', ) ); } class Model_Product extends ORM { protected $_table_name = 'products'; protected $_primary_key = 'id'; protected $_db_group = 'default'; protected $_has_many = array( 'categories' => array( 'model' => 'categorie', 'foreign_key' => 'pr_id', 'through' => 'pr_cats', 'far_key' => 'cat_id', ) ); }
Here is the request in the controller:
$products = ORM::factory('product') ->with('categorie') ->limit($pagination->items_per_page) ->order_by('id') ->offset($pagination->offset) //Какое здесь написать условие что бы выбрало из таблицы products товары с кодом, равным code в таблице categories? ->find_all();