Hi,
I am trying to save return values from the Twitter API, so for example
I have created a model for DirectMessages and Users.
A direct message from Twitter contains a sender and recipient as
nested hashes.
I want to save these objects using the id from Twitter, too.
I convert the hash to models like this:
def convert_direct_message_hash_to_model(dm)
dm["sender"] = User.new(dm["sender"]){|sender| sender.id = dm
["sender"]["id"]}
dm["recipient"] = User.new(dm["recipient"]) {|recipient| recipient.id
= dm["recipient"]["id"]}
DirectMessage.new(dm) {|r| r.id = dm["id"]}
end
then, if I try dm.save! with a self-sent message (so recipient =
sender), I get an SQL error, because user id should be unique. It
seems in this case ActiveRecord attempts to save the objects with an
INSERT statement.
Is there a way to make it update the record if the object already
exists in the db, and otherwise create it?
Also other comments to my approach are welcome, as I am fairly new to
Rails.
Thanks!
Björn
I get the error
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---