Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: OT: Ruby On Rails - your thoughts?

by Fletch (Chancellor)
on Nov 17, 2005 at 18:52 UTC ( #509520=note: print w/replies, xml ) Need Help??


in reply to Re: OT: Ruby On Rails - your thoughts?
in thread OT: Ruby On Rails - your thoughts?

You have to redefine all of your database tables in the Ruby code.

Erm, what? Presuming your tables conform to the Rails conventions (granted that is a substantial caveat when dealing with existing schemas and is an acknowledged weakness of Rails) you need one two line file for each stand alone table. Any relationships between tables are then specified within this class declaration.

class User < ActiveRecord::Base has_many :projects end

With Class::DBI you'd have to have MyDB::User->has_many( projects => "MyDB::Project" ) declarations somewhere to do the same thing, so I don't really see how this is really a substantial deficiency.

Update: Just to clarify, the above declaration would suffice to get a User class which has accessors for all columns of the users table in the default database; it would also setup relationship so that a_user.projects would return an array of Project instances associated with the User instance in question (presuming of course there were an appropriate Project class with a belongs_to :user declaration). If the DB doesn't adhere to Rails' expectations as far as table and primary key names it's pretty simple to correct it (set_table_name "web_user_names"); similar options are available for foreign key names (Class::DBI has similar expectations and mechanisms for allowing variation from them). Additionally, there are code generators which will write the stubs for you so you just run script/generate model User once when creating your app and the grunt work is done; you just go in and add the relationship information.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://509520]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2020-11-24 04:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?