#601 ✓not-applicable
Joe Van Dyk

[PATCH] dm-timestamps doesn't work if no fields have been set

Reported by Joe Van Dyk | October 17th, 2008 @ 09:45 PM

If you do something like Model.create! (so, creating a model without setting anything), and you're using dm-timestamps, you'd expected the created_at fields to be set, right?

Well, they aren't. Think it's because timestamps aren't saved unless the model is #dirty? and it's not if no fields are set.

Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) December 1st, 2008 @ 11:38 AM

    • State changed from “new” to “open”
    • Assigned user changed from “Sam Smoot” to “Dan Kubb (dkubb)”

    Please note there is some private discussion with pdlug on github regarding a similar patch he's provided to Peter's:

    http://github.com/pdlug/dm-more/...

    Here is the message I sent in response to a pull request for this:


    I’ve reviewed the patches and they look good, but I’d like to briefly discuss the spec titled “should set the timestamp fields on creation even for non-dirty objects”.

    One of the things we’re getting more clear on in dkubb/dm-core is what dirty means and how we should deal with it. Dirty now means that if the resource was persisted right now, that it would change the state in the persistence layer, either by creating or changing something. While this sounds simple, it can actually happen in three scenarios:

    1. At least one of the attributes has changed.
    2. No attributes have changed, but there is a serial key
    3. No attributes have changed, and there is no serial key, but at least one of the attributes has a default value

    In the future we’re going to make it so that default values are set at Resource initialization time, rather than lazily as they are now, which will remove condition #3 above.

    Now, I think we only want to update the timestamps if the Resource is dirty. If no attributes have changed, there is no serial key, and no default values, then I don’t think we should persist an essentially null object with timestamp data. In the case of the spec you wrote, I believe GreenSmoothie has a serial key, but we should probably add a pending spec (for when dkubb/dm-core becomes the mainline) that shows that a ModelWithNoDefaultsOrSerialKey.create should not set the timestamp fields.

    Hopefully I’ve explained this well enough. If it doesn’t make sense, please let me know.


    Once pdlug reviews this note and responds I will apply his patch to dm-more.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) December 4th, 2008 @ 03:38 AM

    • State changed from “open” to “hold”

    Changing this ticket to on-hold while I wait for a response from pdlug.

  • Dan Kubb (dkubb)
  • Michael Klishin (antares)

    Michael Klishin (antares) January 10th, 2009 @ 06:39 AM

    • Assigned user set to “Michael Klishin (antares)”
  • Michael Klishin (antares)

    Michael Klishin (antares) March 24th, 2009 @ 02:24 PM

    • State changed from “hold” to “not-applicable”

    I understand OP problem but honestly, this is really an edge case. Checking if model if dirty is something one would often expect for updated_at. I have never seen a case in my projects where absolutely empty model would make sense.

    So for now, please pass those values explicitly in such cases.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Referenced by

Pages