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(); 

    1 answer 1

    And if so:

     // ... ->where('product.code', '=', 'category.code') ->find_all(); 
    • error Unknown column 'product.code' - Demyan112rv
    • And in the Product table in general there is a Code field? - xEdelweiss
    • link goes // table name (column) // products (id) -> pr_cats (pr_id) and categoryes (code) -> pr_cats (cat_id) - Demyan112rv
    • I won't say that I have a lot of desire to guess the structure of your tables and the connections between them, but the construction in the form described above should work provided that you correct the example according to your data - xEdelweiss
    • added table structure to the question - Demyan112rv