Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
ORM Related using incorrect table for where clause
  • I am trying to build a basic search method. http://scrp.at/aII — The factory_name works correctly, but the related (which is many_many) seems to incorrectly do the where clause on the supplier not the related table (see http://scrp.at/aIJ) — the end of the query, as you can see, is using t0 instead of t1. I have also tried this syntax — http://scrp.at/aIK which gives me the same output. This is using 1.1/master. I tried switching to the 1.1/develop and a different issue arises, throwing the following error —
    Fuel\Core\Database_Exception [ 1054 ]: Unknown column '1' in 'on clause'
    
    . The end of the SQL is shown below, which looks like it is using the $_many_many relationship clauses I have setup (http://scrp.at/aIN), but is incorrectly escaping the value.
    FROM `suppliers` AS `t0`
    LEFT JOIN `suppliers_product_types` AS `t1_through` ON (`t0`.`id` = `t1_through`.`supplier_id`)
    LEFT JOIN `product_types` AS `t1` ON (`t1_through`.`product_type_id` = `t1`.`id`
      AND `t1`.`status` = `1` AND `t1`.`deleted` = `0`)
    WHERE `t0`.`deleted` = 0 AND `t1`.`id` IN (4) AND `t1`.`deleted` = 0 ]
    

    I have also tried the DB::select syntax, which generates the correct SQL — http://scrp.at/aIO but when I try to use the as_object hydration, using different methods, I get the following errors:
    as_object('\Model\Supplier') = Exception [ Error ]: Could not execute Model\Supplier::__construct()
    
    as_object('\Supplier') = Fatal error: Class '\Supplier' not found in
    /Users/trovster/Sites/splash/supplier/trunk/fuel/core/classes/database/mysqli/result.php on line 67
    
    as_object('Model_Supplier') = ErrorException [ Compile Error ]: Cannot redeclare class Model\Supplier
    
  • We have discussed this on IRC but thought I would post here for future reference and other people who have the same/similar problem. To have the relation's where apply to that relation rather than the root (i.e. the suppliers table) the above example can be changed to - http://scrp.at/aIY After the update to 1.1/develop the 1 would have had to be expressed as \DB::expr(1) to stop it being escaped as a database table/field, although I do not think this is possible in the relation definition (in which case would be a bug with the Orm package). as_object() on the DB class has been broken for a long time and is not planned to be fixed, easiest way around this is to select the IDs of the main model you want and then to do something similar to Suppliers::find()->where('id', 'IN', $ids)->get();

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion