fuel / orm

Fuel PHP Framework - Fuel v1.x ORM
http://fuelphp.com/docs/packages/orm/intro.html
151 stars 95 forks source link

Temporal correction for multiple primary keys #369

Closed iomariani closed 8 years ago

iomariani commented 9 years ago

This will affect only when you have more primary keys than the default (id, temporal_start, temporal_end);

class Model_Example extends \Orm\Model_Temporal
{
    protected static $_primary_key = array('id', 'fk_id', 'fk2_id', 'temporal_start', 'temporal_end');
}

It will use the function getNonTimestampPks() and add it to the where conditions before sending the query to execute.

Be noted when you use the find, find_revision, find_revisions_between, you must inform all PKs (except temporal ones)

Model_Temporal::find(array($id, $fk_id, $fk2_id));
Model_Temporal::find_revision(array($id, $fk_id, $fk2_id), $temporal_start);
Model_Temporal::find_revisions_between(array($id, $fk_id, $fk2_id), $temporal_start, $temporal_end);

This edit also removed the $relations argument from find_revision. Instead, you should provide the $options, as in any Model\Query instance;

array(
    'related' => array('related1', 'related2', 'relatedN'),
    'where' => array(),
)