This is for a Ruby on Rails 3.0.x project.
I have a "lookup" table with data from a vendor.
When I import data from another source, I want to check this table (join on a SKU) for extra data.
It doesn't seem right to me to create a model for this table in my app. The data will never be changed by my app, and it doesn't need to have any model associations beyond the data lookup I just mentioned. It's just occasionally accessed to check for some info.
What is the best practice to access this table?
Thanks.
There's no harm in creating a model around it, but if you'd like to avoid it, you will have to send raw SQL queries to the DB to get data back as an alternative.
Raw queries: Rails raw SQL example
On the other hand, I think the motivation for wrapping a model around it goes beyond whether or not you want to modify it. I definitely have apps that have models around tables that never change (i.e. a list of app-specific terminology, a list of cities/states, and other static data that is imported once and never changed). ActiveRecord will also wrap the columns into easily accessible methods, so you can read that data easily, not to mention all the convenience methods around sorting, finding, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With