Hi,

I am struggling a bit to find an elegant way to transfer the data from
the API calls to my models and save them in my database.

Was wondering if anybody would be willing to share their ideas? I am
not very experienced with Rails yet.

Atm. I figure the parsed JSON is a hash like parameters from form
input, so the usual ActiveRecord creation methods should work.

I have problems with the ids, though - it seems easier to use the ids
from twitter as primary keys in my db also, and I am not sure how
Rails deals with that. It seems that model.save will not recognise
that the data set already exists by itself (I guess it only knows by
the way an object was created - via new or find). So for example when
I tried to save a self-sent direct message, AR complained about the
duplicate ids (because it would try to insert the sender and recipient
into the db, who are the same user).

My next plan is to add a create_from_twitter_data method to my models
that takes care of the save_or_update stuff and also the associations.
Would be great to hear if there are better ways out there, though.

Björn

Reply via email to