On Jul 22, 2015, at 6:05 AM, Julien Brochet <mewt.fr@gmail.com> wrote:
> Hello!
>
> Thanks for the update. The problem is that I don't have a "Host" table. All informations regarding the host are from my external API. I just want to "extend" those information with dedicated data.
>
Maybe the answer is to cache the API output in a hosts table locally (and add your extra bits at the same time), and then do either a scheduled refresh or make a request against the API on each "show" for a particular host? Then you could update the local cache if there are changes, and everything (local and API data) would stay in synch.
Walter
> Le mercredi 22 juillet 2015 11:57:09 UTC+2, Frederick Cheung a écrit :
>
>
> On Wednesday, July 22, 2015 at 10:52:16 AM UTC+1, Julien Brochet wrote:
> Hello !
>
> I've a question regarding Rails and Active Record.
>
> I've a class, for instance "Host" witch is populated with data from a remote API. I call a specific address and create my object. My object has a specific and unique ID.
>
> I would like to add additional data to this object. This data would be stored in my MySQL database. I want to only store this additional data in my database and do the link with my ID.
>
> My idea for a Rails POV is to add an extra parameter in my "Host" class with something like "host_extra" whitch is an ActiveRecord::Base class with my extra data and in my constructor in my Host class I do a HostExtra.find(id).
>
>
> What do you think of my solution? A better solution exists to do something like that?
>
>
>
>
> You could certainly have a one to one association between this host class and some other table, although it's not clear to me why you wouldn't just store it in the hosts table (not to say that there can't be a good reason for this, you just haven't said why you want to do this).
>
> Fred
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/685b7196-8af5-4a9e-809f-7c5d1931ef6b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9A3E58B8-6050-47E0-8D73-49485C2CFF82%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment