Andrew Stuart
2005-Mar-18 22:43 UTC
Newbie question: Rails as a solution for existing databases
Hello, I seem to be getting the picture that Rails is great for situations in which the developer is able to specify the database schema/structure. Is it just as good at being used on existing database schemas that have not been designed to be "Rails friendly"? Or does Rails have limitations and expectations of the database schema that makes it impratical to apply to existing databases? Please forgive me if it is an obvious question - I am yet a newbie with Rails. Cheers Andrew Stuart
David Adams
2005-Mar-18 22:47 UTC
Re: Newbie question: Rails as a solution for existing databases
I''m not an expert on ActiveRecord, but I can speak from my experience thus far. If your existing databases follow basic relational principles, eg foreign keys, join tables, normalized data, then it shouldn''t be too difficult to define Models on top of them. It''s always possible in ActiveRecord to specify the foriegn key name and table name for relationships and definitions. I''ve had good luck with this type of thing, at least. -dave On Sat, 19 Mar 2005 09:43:41 +1100, Andrew Stuart <andrew.stuart-HYVr4Vs6GMsQrrorzV6ljw@public.gmane.org> wrote:> Hello, > > I seem to be getting the picture that Rails is great for situations in which > the developer is able to specify the database schema/structure. > > Is it just as good at being used on existing database schemas that have not > been designed to be "Rails friendly"? > > Or does Rails have limitations and expectations of the database schema that > makes it impratical to apply to existing databases? > > Please forgive me if it is an obvious question - I am yet a newbie with > Rails. > > Cheers > > Andrew Stuart > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Kevin McConnell
2005-Mar-19 00:21 UTC
Re: Newbie question: Rails as a solution for existing databases
David Adams wrote:> I''m not an expert on ActiveRecord, but I can speak from my experience > thus far. If your existing databases follow basic relational > principles, eg foreign keys, join tables, normalized data, then it > shouldn''t be too difficult to define Models on top of them.What about databases that don''t use auto-incrementing integers for keys (for situtations where a natural primary key already exists, and so on) ? I wasn''t able to find much in the documentation about that. Thanks, Kevin
Kevin McConnell
2005-Mar-19 01:42 UTC
Re: Newbie question: Rails as a solution for existing databases
Kevin McConnell wrote:> What about databases that don''t use auto-incrementing integers for keys > (for situtations where a natural primary key already exists, and so on) > ? I wasn''t able to find much in the documentation about that.Whoops - went looking again and it turned out to be really simple. Posting this folow up just in case it''s helpful to the OP. You can specify the primary_key name with (duh) self.primary_key, as in: class Report < ActiveRecord::Base def self.table_name() ''report''; end def self.primary_key() ''report_id'' end end But be aware that its value will use the accessor "id", not "report_id": r = Report.new() r.id = 123 Cheers Kevin