• CommentAuthorBeanz
    • CommentTimeFeb 4th 2010
     

    Recently Lolly asked me to help him with an intranet application, which I thought immediately, "Symfony is the thing for that".
    I then noticed that there is a (not quite so) new version, Symfony 1.4.1, which has several differences to the previous versions.

    The most noticeable difference is the choice of Doctrine rather than Propel for database abstraction.
    I have found that the documentation for Propel for my last experiments has been rather good, with a very useful schema cheat-sheet (http://andreiabohner.wordpress.com/2007/09/01/symfony-cheat-sheet-schema/). Doctrine, however, has been lacking in API documentation.

    I have investigated the doctrine behaviours in the configuration, notably the "Timestampable" behaviour which should behave (as documented) by adding "created_at" and "updated_at" columns, which should do the obvious thing.
    Test Schema:

    Test: actAs: [Timestampable] columns: name: string(255)

    I then generated an application from my model, and I was stumped.
    For some reason, as the model now includes these 2 fields, they're required when creating new objects when being validated. If you then put in information that's not the current date/time, it will set it to them, rather than the actual values they should be.
    After much huffing and puffing I have now worked out the solution; which is almost understandable, if very annoying.

    Doctrine and Symfony assume that you might want to be able to manually edit the created_at or updated_at fields, so you can lie about these things. In order to get the expected behaviour I needed to make some changes:

    • In the forms folder (lib/form/doctrine/) I edited the TestForm.class.php:
      In the configure() method, I added:

      unset($this->widgetSchema['created_at']); unset($this->validatorSchema['created_at']); unset($this->widgetSchema['updated_at']); unset($this->validatorSchema['updated_at']);

      This then removes the widgets from the form (so I don't have to see them! :)) and then tells it that they're not required to be validated.

    • As I had generated the form before making these changes, I then needed to remove the extra form widgets from the template.

    Now it works with the expected behaviour,
    When I create a new entry, the created_at and updated_at are now at the correct times, and when I edit it, the updated_at updates without any extra magic.
    I just wish someone had put this information in an easy to find place so I knew why it wasn't doing what it told me it'd do! :(

    • CommentAuthorGuest
    • CommentTimeMar 11th 2010
     

    Nice

    • CommentAuthorGuest
    • CommentTimeMar 11th 2010
     

    Nice

    • CommentAuthorGuest
    • CommentTimeMar 11th 2010
     

    A faster way of doing it

    unset(
    $this['created_at'], $this['updated_at']
    );

    :)

    •  
      CommentAuthorSpode
    • CommentTimeMar 13th 2010
     

    Nice Beanz :)

 
Copyright Andrew Miller (Spode), 2008