Guys have working SQL:
Symfony 1.4:
$query = Doctrine_Query::create() ->from('TechAnalys ta') ->leftJoin('ta.Translation tatr') ->leftJoin('ta.TCInstrument tci') ->leftJoin('tci.primarygroup cat') ->andWhere('ta.isActive=?', 1) ->andWhereIn('tatr.lang', $this->trans_langs) ->andWhere('tatr.isTActive =?', 1) ->orderBy('ta.created_at DESC'); private function getPager($query, $page) { $pager = new sfDoctrinePager('TechAnalys', 10); $pager->setQuery($query); $pager->setPage($page); $pager->init(); return $pager; } Resultat:
SELECT * FROM techanalys t LEFT JOIN techanalys_translation t2 ON t.id = t2.id LEFT JOIN t_c_instrument t3 ON t.t_c_instrument_id = t3.id LEFT JOIN trading_condition_groups t4 ON t3.primarygroupid = t4.id WHERE ( t.isactive = 1 AND t2.lang IN ('en') AND t2.istactive = 1 ) ORDER BY t.created_at DESC That is, it will be displayed similar
id title isretro created_at updated_at 1 aaa 0 2017-01-10 2017-01-10 2 bbb 1 2017-01-09 2017-01-09 3 ccc 0 2017-01-08 2017-01-08 4 ddd 1 2017-01-07 2017-02-01 5 eee 1 2017-01-06 2017-02-10 The techanalys t table has an techanalys t column with a value of 0 or 1, and the updated_at column shows when it is created.
It is necessary to do the following: Imagine that there are 5 records. Where 3 lines need to be duplicated and added to the main result. That is, it turns out 6 lines.
From the main query, select those that isretro and add to the main result. For isretro -> updated_at , and for normal -> created_at. It turns out to duplicate this line and insert it in the appropriate place, taking their time into account. The priority is at isretro .
If in this query it would be great to be able to select separately those that isretro and combine with the main result, considering the date.
Maybe showing the result that I want to get more accurately expresses what I want:
id title isretro created_at updated_at 5 eee 1 2017-01-06 2017-02-10 4 ddd 1 2017-01-07 2017-02-01 1 aaa 0 2017-01-10 2017-01-10 2 bbb 1 2017-01-09 2017-01-09 2 bbb 1 2017-01-09 2017-01-09 3 ccc 0 2017-01-08 2017-01-08 4 ddd 1 2017-01-07 2017-02-01 5 eee 1 2017-01-06 2017-02-10 Thank.