Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Orm Save does reload from db, Model_CRUD does
  • If I forge and save an object that extends from Orm\Model, values that are populated by the database are not pulled back into the object (created_at, modified_at, etc).  Is this normal?  It's really screwing me up as I move from Model_Crud (reason for move is a couple of compound key tables).  Is there any way to force this behavior?  I'm on 1.7.1.
  • Not really sure what you mean.

    Neither Model_Crud nor ORM does a re-read of the record after a save. So (this is what I assume) if you use something like DEFAULT in a MySQL column, the default assigned value when you insert a new row will not be present in either of them?
  • Harro, I see now that you are right, my CRUD models allowed me to do this:

        protected static $_mysql_timestamp = TRUE;
        protected static $_created_at = 'created_at';
        protected static $_updated_at = 'updated_at';

    And populated the values for me.  I moved these into properties, but couldn't have expressions in my static properties (eg. array('default'=>time()).  Do I need to use observers to achieve the same thing here?

  • HarroHarro
    Accepted Answer
    In ORM, you indeed need observers for that. For these two, standard observers are present, see

    You can not have expressions in property definitions. If you have a need for them, define an _init() static method, and put the code to complete your definitions in there. We use it all the time, for example to populate option arrays (for dropdowns on forms), or to add language specific defaults.
  • That was the ticket, sorry I missed it.

Howdy, Stranger!

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

In this Discussion