← Back to Upcase

Associating API data with my Rails model


(Maurice Womack) #1

I have an app that pulls in venue info from Foursquare. I want to be able to add a Comment model that is associated with the Foursquare venue info (i.e a venue has_many comments). However, I do not have a venue model as this . I am wondering how do I associate my Comment model with the Foursquare venue info? SInce I don’t have a Venue model, how can my Comment “belongs_to” a venue?

Any advice on how to approach this would be appreciated.


(Charlieanna) #2

What do you mean that you do not have a venue model?


(Maurice Womack) #3

Because I’m pulling data from Foursquare and displaying it, I didn’t create a venue model. Should I?


(Charlieanna) #4

Yes. If you are sure that you need a Venue model always.


(Maurice Womack) #5

What if don’t create a venue model? Just for my information, how would I associate my Comment model with info from Foursquare? For example, what replaces “belongs_to” in this instance?


(Maurice Womack) #6

No on else has any thoughts?


(Robert Lee-Cann) #7

If you don’t need to know the venue details, only Foursquare’s internal venue ID for the particular comment, then could you just use a single field in the comment - i.e. no association needed.

Of course, if you ever want to return the venue name or other details to your users alongside the comments, then it’s probably useful to pull this data in from Foursquare and store locally in a model, if only to stop having to do API calls to Foursquare over and over to get this info.


(Maurice Womack) #8

Okay, that helps. I’m thinking I should create a venue model :slight_smile: Thanks.