ruby - Updating a property set as the key in DataMapper -
is possible update property in datamapper if :key
set true?
say, example, have model set this:
class post include datamapper::resource property :slug, text, :unique => true, :key => true # ... end
and made new instance of :slug => "example-post-title"
.
i tried update accessing stored
@post = post.get("example-post-title") #=> #<post @slug="example-post-title" ...> @post.slug = "example-post-title-2" #=> "example-post-title-2" @post.save #=> true @post = post.get("example-post-title-2") #=> nil
but can see slug never updated. tried using post#update
method:
@post = post.get("example-post-title") #=> #<post @slug="example-post-title" ...> @post.update(:slug => "example-post-title-2") #=> true @post = post.get("example-post-title-2") #=> nil
looking in database, index column not changed either of these examples. remains example-post-title
rather example-post-title-2
.
according docs, post#update
method, similar post#save
method, should return true if operation successful, , false if not. returning true
here, it's not updating record.
i've searched , searched , can't find on internet. neither stackoverflow nor datamapper rdoc had updating key.
i know can have unique serial
property , instances of post
using slug (as in, make serial
property key instead of slug), i'm looking way without that, if @ possible.
my hunch can't update key. according doc, protected against mass assignment:
natural keys protected against mass-assignment, setter= need called individually if you're looking set them.
they don't talk updating them in "key => value" stores impossible or deprecated update key. i'd assume that's case here well, though can't find hard evidence give : /
Comments
Post a Comment