Hi Solnic,
Yes, using after :create makes more sense.
I still have the problem that although the url property is then
successfully created, it is not persisted itself.
Should I save again? That seems wasteful to have 2 saves for every
page created.
class Page
include DataMapper::Resource
property :id, Serial
property :url
after :create do
self.url ='/mysite/' << self.id.to_s
self.save
end
end
cheers,
DAZ
On Apr 3, 12:05 pm, Piotr Solnica <[email protected]> wrote:
> Hey,
>
> Yes, Serial value is returned from the adapter and is set once a new
> resource is created (persisted). You should use after :create hook
> here since after :save is called also when you update an existing
> resource which would not make any sense since Serial will not be
> changing.
>
> Cheers!
>
> # solnic
>
> On Apr 3, 12:41 pm, DAZ <[email protected]> wrote:
>
>
>
>
>
>
>
> > I think that serial properties don't get set until the resource is
> > saved.
>
> > I tired using an after :save hook to set the url property using the
> > id. This worked, but the url property wasn't saved!
>
> > There must be a standard way of setting property values that are based
> > on the id .... isn't there?
>
> > cheers,
>
> > DAZ
>
> > On Apr 1, 10:50 pm, DAZ <[email protected]> wrote:
>
> > > Hi,
>
> > > I'm trying to use the id of a resource to set a default value, but nil
> > > keeps getting returned as the id:
>
> > > eg
>
> > > class Page
> > > include DataMapper::Resource
> > > property :id, Serial
> > > property :url, Text, :default => Proc.new { |r, p| ('/
> > > mysite/'+r.id.to_s }
> > > end
>
> > > Am I doing something stupid here?
>
> > > cheers,
>
> > > DAZ
--
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en.