Linking API derived data to my application's database

Hi guys,

Given a page that retrieves data from a 3rd party API, how would you
then go about associating additional info in the application's
database with that record?

Specifically, the page displays info on a product, and I'd like to
store and display locally created reviews for that product.

To display the product I'm using a route of the form /product/
<productid> where the productid is the barcode of the product. The
barcode is used in the controller to look up the data via the 3rd
party API.

It's the structure of the database / model and how to link one the
other that I'm struggling with conceptually. (I'm a relatively newbie
with Rails, Ruby & ActiveRecord, and programming in general (!) so
please forgive me if this is painfully obvious!)

Many thanks in advance for any advice or suggestions...

Matt.

MattB wrote:

Hi guys,

Given a page that retrieves data from a 3rd party API, how would you
then go about associating additional info in the application's
database with that record?

Specifically, the page displays info on a product, and I'd like to
store and display locally created reviews for that product.

To display the product I'm using a route of the form /product/
<productid> where the productid is the barcode of the product. The
barcode is used in the controller to look up the data via the 3rd
party API.

It's the structure of the database / model and how to link one the
other that I'm struggling with conceptually. (I'm a relatively newbie
with Rails, Ruby & ActiveRecord, and programming in general (!) so
please forgive me if this is painfully obvious!)

Many thanks in advance for any advice or suggestions...

Matt.

Seems like you've answered your own question. I'd keep it simple. Make
the barcode value a uniquely-indexed attribute of your own product
record (with it's id field). Use the id field for all your rails coding
- the product record and parent id of the child review records, and use
the barcode value to access the external 3rd party API data.

Hi Ar,

That's pretty much how I'd originally structured it when I was using
all locally derived data - a products table and a reviews table, along
the lines of the posts / comments example in the Getting Started with
Rails Guide, with the barcode stored in the products table, in turn
used to look up item attributes from the API.

So: /products/<id>/reviews/<id> with <id> referencing the database id
field. All fine so far.

However, now I have a model-less /products/<barcode> that can display
any item, for which all data is coming from the API, and for which
there's no product record, may or may not have reviews, ie. It's
possible to search for and display data for _any_ product that the API
has data for, with no local database involved, hence I don't have a
product_id field to code around.

That's where I'm struggling (and probably mostly because I'm coding by
example and haven't found a suitable example to borrow from).

Thanks,
Matt.