Hi guys - I have been searching and searching but I am just so confused.
Here is my situation:
I am working on a front-end to an existing database. It's strictly
lookup, no create/update/drop - just trying to get data out in a pretty
way. I was hoping to do this in RoR as a learning exercise, and as a
first step towards moving our web-apps to a more standard platform
(right now they are a jumble of php, javascript, etc)
Here's my big problem:
Because of the way our db is structured, I can't make a read-only user
account (this is stupid, I know, but unfortunately our dbadmin won't
budge) - so I am concerned that if I make a migration, I might end up
changing the db structure and affecting other users. I need a way to
access the database that won't allow RoR to make any db changes at all -
just the R part of crud...
Here's my smaller problem:
I want to acccess several databases at once - some of my data is on a
MSSQL server, some on a MySQL server...
Am I barking up the wrong tree with RoR? This was easy (but MESSY) to do
in php, but I'd really like to be using RoR as it seems like the way
things are moving...
ruby script/generate model Category --skip-migration
Open up /app/models/widget.rb and make it look like this:
class Widget < ActiveRecord::Base
set_table_name “widget”
set_primary_key “widget_id”
belongs_to :category
end
Now open up /app/models/category.rb and make it look like this:
class Widget < ActiveRecord::Base
set_table_name “category”
set_primary_key “category_id”
has_many :widgets
end
That should take care of the two biggest issues - id and table names. Other things to watch out for are field names. If you have field names with spaces, dashes, or other characters, life gets much more difficult.