Now.. that is interesting
To be honest, I've only ever used setting the id to a specific value
on a new record... not on an existing one.
The problem is that the following code in
rails/activerecord/lib/base.rb is what does the update:
def update(attribute_names = @attributes.keys)
quoted_attributes = attributes_with_quotes(false, false,
attribute_names)
return 0 if quoted_attributes.empty?
connection.update(
"UPDATE #{self.class.quoted_table_name} " +
"SET #{quoted_comma_pair_list(connection, quoted_attributes)} " +
"WHERE
#{connection.quote_column_name(self.class.primary_key)} =
#{quote_value(id)}",
"#{self.class.name} Update"
)
end
As you can see, the WHERE clause is going to use id to find the record
we are after, as you set id to a different value... that won't
work....
This code would have to be updated to allow id to be set using a
"new_id" and "old_id" value pair...
I think this is enough of an edge case though that you would be better
served by making a new record and deleting the old one...
like so:
a = Account.find(1)
new_account = Account.new(a.params)
new_account.id = new_id
new_account.save
*should* work :)
Mikel
--
http://lindsaar.net/
Rails, RSpec and Life blog....
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" 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/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---