Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
ORM - select one field only
  • How can I get only one field using query?

    Model_Product_CustomColor::query()->select('idProduct')->where('idCustomColor', 'IN', $category_values)->get-query();

    shows:

    SELECT `t0`.`idProduct` AS `t0_c0`, `t0`.`id` AS `t0_c1` FROM
    `product_custom_color` AS `t0` WHERE `t0`.`idCustomColor` IN ('1', '3',
    '4', '7');

    And I don't want id here because it should be used as subquery...

    Thanks,
    Robert
  • What Fuel version are you on?

    Just tried this in a 1.6/develop install (which is the same code as the 1.5.1. release), and I don't see the PK being inserted.
  • I use 1.4 version
  • I updated to 1.5.1 and still the same. Model:

    class Model_Product_CustomColor extends \Orm\Model
    {
        protected static $_table_name = 'product_custom_color';
        protected static $_properties = array(
            'id',
            'idProduct',
            'idCustomColor'
        );

          
        protected static $_belongs_to = array(
            'product' => array(
                'key_from' => 'idProduct',
                'model_to' => 'Model_Product',
                'key_to' => 'id',
            ),
            'color' => array(
                'key_from' => 'idCustomColor',
                'model_to' => 'Model_Dictionary_Product_CustomColor',
                'key_to' => 'id',
            )
        );
    }
  • I just copied this model into a fresh 1.5 installation, and added
    \Package::load('orm');
    var_dump((string) Model_Product::query()->select('idProduct')->where('idCustomColor', 'IN', array(1,2,3))->get_query());
    to the welcome controller index method.

    Output:
    string 'SELECT `t0`.`idProduct` AS `t0_c0` FROM `product_custom_color` AS `t0` WHERE `t0`.`idCustomColor` IN (1, 2, 3)' (length=110)		
  • Are you sure your Orm package it up to date too?
  • You are right, after updating packages all works great.

    Thanks
  • HarroHarro
    Accepted Answer
    Cool. Thanks for the feedback.

Howdy, Stranger!

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

In this Discussion