Skip to content
This repository has been archived by the owner on Jun 30, 2018. It is now read-only.

Default date value for on published_on #459

Closed
amir20 opened this issue Sep 18, 2012 · 2 comments
Closed

Default date value for on published_on #459

amir20 opened this issue Sep 18, 2012 · 2 comments

Comments

@amir20
Copy link

amir20 commented Sep 18, 2012

I have been reading the code for how a property default value is defined. It seems like something like:

property :published_on, type: 'date', default: Date.new

Would not work because it would cache the default value to now at that time. Is this the correct assumption?

@karmi karmi closed this as completed in 6721c85 Oct 18, 2012
@karmi
Copy link
Owner

karmi commented Oct 18, 2012

Exactly. I've added the ability to define the default value as lambda (see the closing commit):

class MyModel
  include Tire::Model::Persistence

  property :created_at, :default => lambda { Time.now }
end

Note though, that the lambda is evaluated when you create the object, not when you access the property.

@amir20
Copy link
Author

amir20 commented Oct 18, 2012

Great! Will try.

NOX73 pushed a commit to NOX73/tire that referenced this issue Oct 23, 2012
…ce as lambdas

Now, it's possible to do:

    class MyModel
      include Tire::Model::Persistence

      property :created_at, :default => lambda { Time.now }
    end

Note though, that the lambda is evaluated when you create the object, not when you access the property.

Closes karmi#459
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants