Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Orm cuts data in object from query results
  • Hi i got problem with one of my orm query because I found that query generated by orm return good data set but in orm result object data is missing:

    orm model query:
    $articles = \Model_Article::find('all', array(
                    'related' => array(
                        'category' => array(
                            'where' => array(array('category_id', 'IN', $categories)),
                        ),
                        'galleries' => array(
                            'join_type' => 'left outer',
                            'join_on' => array(array('status', '=', '1')),
                        ),
                        'photos' => array(
                            'join_type' => 'left outer',
                            'join_on' => array(array('type','=','2')),
                            'related' => array('server'),
                        ),
                    ),
                    'where' => array(array('active', '=', 1)),
                    'rows_limit' => $pagination->per_page,
                    'rows_offset' => $pagination->offset,
                    'order_by' => array('update_at_date' => 'desc', 'update_at_time' => 'desc'),
                    'from_cache' => false,
                    'group_by' => array('id'),
                ));
    here is sample query generated by orm:
    SELECT 
    `t0`.`id` AS `t0_c0`,
    `t0`.`title` AS `t0_c1`,
    `t0`.`title_alt` AS `t0_c2`,
    `t0`.`meta_title` AS `t0_c3`,
    `t0`.`intro` AS `t0_c4`,
    `t0`.`intro_alt` AS `t0_c5`,
    `t0`.`flags` AS `t0_c6`,
    `t0`.`flags_adv` AS `t0_c7`,
    `t0`.`create_at_date` AS `t0_c8`,
    `t0`.`create_at_time` AS `t0_c9`,
    `t0`.`update_at_date` AS `t0_c10`,
    `t0`.`update_at_time` AS `t0_c11`,
    `t0`.`active` AS `t0_c12`,
    `t0`.`add_by_id` AS `t0_c13`,
    `t0`.`update_by_id` AS `t0_c14`,
    `t0`.`source` AS `t0_c15`,
    `t0`.`url` AS `t0_c16`,
    `t0`.`counter_arch` AS `t0_c17`,
    `t1`.`id` AS `t1_c0`,
    `t1`.`category_id` AS `t1_c1`,
    `t1`.`article_id` AS `t1_c2`,
    `t1`.`main` AS `t1_c3`,
    `t2_through`.`gallery_id`,
    `t2_through`.`article_id`,
    `t2`.`id` AS `t2_c0`,
    `t2`.`name` AS `t2_c1`,
    `t2`.`name_alt` AS `t2_c2`,
    `t2`.`intro` AS `t2_c3`,
    `t2`.`status` AS `t2_c4`,
    `t2`.`rate` AS `t2_c5`,
    `t3_through`.`photo_id`,
    `t3_through`.`article_id`,
    `t3`.`id` AS `t3_c0`,
    `t3`.`user_id` AS `t3_c1`,
    `t3`.`server_id` AS `t3_c2`,
    `t3`.`width` AS `t3_c3`,
    `t3`.`height` AS `t3_c4`,
    `t3`.`name` AS `t3_c5`,
    `t3`.`description` AS `t3_c6`,
    `t3`.`status` AS `t3_c7`,
    `t3`.`rating` AS `t3_c8`,
    `t3`.`ext` AS `t3_c9`,
    `t3`.`hash` AS `t3_c10`,
    `t3`.`for_adults` AS `t3_c11`,
    `t3`.`source_id` AS `t3_c12`,
    `t3`.`type` AS `t3_c13`,
    `t4`.`id` AS `t4_c0`,
    `t4`.`name` AS `t4_c1`
    FROM
    `articles` AS `t0`
    LEFT JOIN
    `article_categories` AS `t1` ON (`t0`.`id` = `t1`.`article_id`)
    LEFT OUTER JOIN
    `article_galleries` AS `t2_through` ON (`t0`.`id` = `t2_through`.`article_id`)
    LEFT OUTER JOIN
    `galleries` AS `t2` ON (`t2_through`.`gallery_id` = `t2`.`id`)
    LEFT OUTER JOIN
    `article_photos` AS `t3_through` ON (`t0`.`id` = `t3_through`.`article_id`)
    LEFT OUTER JOIN
    `photos` AS `t3` ON (`t3_through`.`photo_id` = `t3`.`id`
    AND `t3`.`type` = '2')
    LEFT JOIN
    `servers` AS `t4` ON (`t3`.`server_id` = `t4`.`id`)
    WHERE
    `t0`.`active` = 1
    AND `t1`.`category_id` IN ('31' , '32', '39')
    GROUP BY `t0`.`id`
    ORDER BY `t0`.`update_at_date` DESC , `t0`.`update_at_time` DESC
    LIMIT 4 OFFSET 0
    here is sample data returned by query in json format:
    [
    {
    't0_c0' : 18,
    't0_c1' : 'add 2',
    't0_c2' : '',
    't0_c3' : '',
    't0_c4' : 'kajshdfkl jahs lkdjfhalksjdfh laksjdfhl',
    't0_c5' : '',
    't0_c6' : 24,
    't0_c7' : 13,
    't0_c8' : '2014-02-24',
    't0_c9' : '14:15:32',
    't0_c10' : '2014-03-06',
    't0_c11' : '15:23:57',
    't0_c12' : 1,
    't0_c13' : 5,
    't0_c14' : 5,
    't0_c15' : '',
    't0_c16' : 'add_2',
    't0_c17' : 0,
    't1_c0' : 42,
    't1_c1' : 32,
    't1_c2' : 18,
    't1_c3' : 1,
    'gallery_id' : NULL,
    'article_id' : NULL,
    't2_c0' : NULL,
    't2_c1' : NULL,
    't2_c2' : NULL,
    't2_c3' : NULL,
    't2_c4' : NULL,
    't2_c5' : NULL,
    'photo_id' : 32,
    'article_id' : 18,
    't3_c0' : 32,
    't3_c1' : 5,
    't3_c2' : 1,
    't3_c3' : 320,
    't3_c4' : 240,
    't3_c5' : 'kajshdakjsh',
    't3_c6' : 'kajshdkajsh',
    't3_c7' : 1,
    't3_c8' : 0,
    't3_c9' : 'jpg',
    't3_c10' : '6e4d5a5e942f4f55af4c00f60490d98d',
    't3_c11' : 0,
    't3_c12' : 30,
    't3_c13' : 2,
    't4_c0' : 1,
    't4_c1' : ''
    },
    {
    't0_c0' : 15,
    't0_c1' : 'test',
    't0_c2' : '',
    't0_c3' : '',
    't0_c4' : 'ajshdkjahskdjahksjd',
    't0_c5' : '',
    't0_c6' : 24,
    't0_c7' : 13,
    't0_c8' : '2014-01-09',
    't0_c9' : '09:38:14',
    't0_c10' : '2014-02-28',
    't0_c11' : '00:27:08',
    't0_c12' : 1,
    't0_c13' : 5,
    't0_c14' : 5,
    't0_c15' : '',
    't0_c16' : 'test',
    't0_c17' : 0,
    't1_c0' : 34,
    't1_c1' : 31,
    't1_c2' : 15,
    't1_c3' : 0,
    'gallery_id' : NULL,
    'article_id' : NULL,
    't2_c0' : NULL,
    't2_c1' : NULL,
    't2_c2' : NULL,
    't2_c3' : NULL,
    't2_c4' : NULL,
    't2_c5' : NULL,
    'photo_id' : 23,
    'article_id' : 15,
    't3_c0' : 23,
    't3_c1' : 5,
    't3_c2' : 1,
    't3_c3' : 320,
    't3_c4' : 240,
    't3_c5' : 'Chryz',
    't3_c6' : 'Chryz',
    't3_c7' : 1,
    't3_c8' : 0,
    't3_c9' : 'jpg',
    't3_c10' : '31ddbdee4a8c749227c813b24918aeb9',
    't3_c11' : 0,
    't3_c12' : 21,
    't3_c13' : 2,
    't4_c0' : 1,
    't4_c1' : ''
    },
    ]
    but when these data is converting to orm model object only first element have related photos model and rest have that relation empty event if query return data perfectly because I check result in mysql workbench to see what data return that query. I wonder why these data is missing in orm object?

  • Which version of Fuel?
  • Fuel 1.7.1
  • HarroHarro
    Accepted Answer
    I have never seen that before, or experienced in our applications.

    Why is "from_cache" set to false? That might have something to do with it, it's not reliable for complex queries. And it is virtually never needed, especially not for these large selects.
  • I found bug but it's not a framework but mysql version in older version group by is working little diffirent and cuts results when grouping.

    Thanks Harro

Howdy, Stranger!

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

In this Discussion