#1087 ✓not-applicable
ojak

dm-timestamps not setting default timestamp (dm-0.10.1)

Reported by ojak | October 8th, 2009 @ 04:03 AM

dm-timestamps does not appear to be setting created_at and updated_at to the current time by default. The following error occurs:

"Field 'updated_at' doesn't have a default value"

Comments and changes to this ticket

  • Jonathan Stott (namelessjon)

    Jonathan Stott (namelessjon) October 9th, 2009 @ 08:42 AM

    • State changed from “new” to “hold”
    • Tag set to 0.10.1, dm-timestamp

    I can't duplicate the problem you're seeing with the simple script I tried (attached). Could you please modify it until it shows the problem you're seeing? Alternatively, if the script does show the probably, could you state which ruby you're using?

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) November 6th, 2009 @ 02:13 AM

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

    Marking as not-applicable due to no response from submitter.

  • sliu

    sliu January 13th, 2010 @ 12:09 AM

    exception occurs if I change model.create to model.create!
    It seems the "DataMapper.auto_migrate!" genereate NOT NULL columns, while timestamps plugin didn't set the value when save to DB.

    plz reconsider the situation, thx.

  • sliu

    sliu January 13th, 2010 @ 01:16 AM

    sorry, I remember Dan explained that on groups before.
    DM treat create! as force create(without any hook, which is used to implement timestamps and so on), not AR's style.
    I checked DM's source code and it proved this.
    This protocol makes sense, but how about to invent a machanism to catelog different aspects/hooks, and then decide whether they should be included in the force create or not.
    further more, decide the hooks' order/stage, via specifying some stage point.
    That's my suggestion:

    module DataMapper::Resource
    include Extlib::Hook register_instance_hook :save, :before, :stages => [:set_data, :validation] end

    model.before :save, :set_timestamps, :stage => :set_data
    model.before :save, :validate_attributes, :stage => :validate

    save! should call hooks in :set_data stage, but ignore others.

    NEED to change Extlib::Hook's source.
    What's your opinion?

    refer the latest DM's implementations.
    dm-core/resource.rb

    def save
    _save(true) end

    def save!
    _save(false) end

    _save called _save_self

    create_hook is used to apply before/after hooks, while _create is pure/unpolluted

    def save_self(safe = true)

      new_resource = new?
      if safe
        new_resource ? create_hook : update_hook
      else
        new_resource ? _create : _update
      end
    end
    

    end

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 »

Pages