On Sun, 16 Aug 2009 15:55:39 +0100
Ashley Moran <[email protected]> wrote:
>
>
> On 15 Aug 2009, at 09:00, Dan Kubb (dkubb) wrote:
>
> > I'm not precisely sure what the best approach to this is. In a web
> > app, this will probably never be an issue since the general pattern is
> > to update the resource in one step. Either approach we decide on
> > probably won't affect web apps. However, I am trying to make sure it
> > acts in a consistent manner for other use-cases, taking into account
> > POLS.
>
> Hi Dan/everyone
>
> Can anyone describe a situation where #update is useful? I ask
> because I've never found one, which may be because I work almost
> entirely on web apps.
>
> Ashley
>
# using sinatra for an example webapp.
put "/posts/:id" do
@post = Post.first(:id => params[:id])
attributes = params[:post].only(:body, :title)
if @post.update(attributes)
redirect '/post/1'
else
erb :errors_template
end
end
It does, admittedly, only save 1 line over '@post.attributes= ...,@post.save'.
It's probably more useful when applied at the Collection or Model level, for
example:
User.all(:last_login_at.lte => 60.days.ago).update(:inactive => true)
But it's the intention to make the resource, collection and model APIs as
similar as possible.
Regards
Jon
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---