nikola.borisof-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Mar-26 00:53 UTC
Ruby on Rails Database with foreign keys?
Hi, I started a project on Ruby on Rails some time ago when the migration feature wasn''t part of Rails. I used to have one big SQL file that creates the whole database and adds the foreign constraints. They looked like that: CONSTRAINT FK_users_countries FOREIGN KEY FK_users_countries (country_id) REFERENCES countries(country_id) ON DELETE RESTRICT ON UPDATE RESTRICT Now I want to use migration features so I used rake db:schema:dump When I look at the schema.rb file i don''t like what i see ;(. All the tables are there but the are no primary keys and also there are no Foreign Keys. My question is can i use the ruby way to create foreign keys? And why rake db:schema:dump doesn''t work? Nikola --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rails nerds are not big on FKs - I don''t like it but if want to play along - learn to. You can put FK constraints in your migrations as SQL statements - execute """ ALTER ..... """ The FK don''t show up in the schema.rb - See first statement above They cause problems with fixtures - See first statement above On Mar 25, 2:53 pm, "nikola.bori...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <nikola.bori...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I started a project on Ruby on Rails some time ago when the migration > feature wasn''t part of Rails. I used to have one big SQL file that > creates the whole database and adds the foreign constraints. They > looked like that: > > CONSTRAINT FK_users_countries > FOREIGN KEY FK_users_countries (country_id) > REFERENCES countries(country_id) > ON DELETE RESTRICT > ON UPDATE RESTRICT > > Now I want to use migration features so I used > > rake db:schema:dump > > When I look at the schema.rb file i don''t like what i see ;(. All the > tables are there but the are no primary keys and also there are no > Foreign Keys. > > My question is can i use the ruby way to create foreign keys? And why > > rake db:schema:dump > > doesn''t work? > > Nikola--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
google for the foreign key migrations plugin from redhill consulting. I use that on my rails apps and it works great. On 3/25/07, dysinger <dysinger-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Rails nerds are not big on FKs - I don''t like it but if want to play > along - learn to. > > You can put FK constraints in your migrations as SQL statements - > execute """ ALTER ..... """ > > The FK don''t show up in the schema.rb - See first statement above > > They cause problems with fixtures - See first statement above > > On Mar 25, 2:53 pm, "nikola.bori...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" > <nikola.bori...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi, > > > > I started a project on Ruby on Rails some time ago when the migration > > feature wasn''t part of Rails. I used to have one big SQL file that > > creates the whole database and adds the foreign constraints. They > > looked like that: > > > > CONSTRAINT FK_users_countries > > FOREIGN KEY FK_users_countries (country_id) > > REFERENCES countries(country_id) > > ON DELETE RESTRICT > > ON UPDATE RESTRICT > > > > Now I want to use migration features so I used > > > > rake db:schema:dump > > > > When I look at the schema.rb file i don''t like what i see ;(. All the > > tables are there but the are no primary keys and also there are no > > Foreign Keys. > > > > My question is can i use the ruby way to create foreign keys? And why > > > > rake db:schema:dump > > > > doesn''t work? > > > > Nikola > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
There is a plugin, from RedHill consulting, that allow you create FK´s: http://www.redhillconsulting.com.au/rails_plugins.html 2007/3/25, dysinger <dysinger-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > > Rails nerds are not big on FKs - I don''t like it but if want to play > along - learn to. > > You can put FK constraints in your migrations as SQL statements - > execute """ ALTER ..... """ > > The FK don''t show up in the schema.rb - See first statement above > > They cause problems with fixtures - See first statement above > > On Mar 25, 2:53 pm, "nikola.bori...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" > <nikola.bori...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi, > > > > I started a project on Ruby on Rails some time ago when the migration > > feature wasn''t part of Rails. I used to have one big SQL file that > > creates the whole database and adds the foreign constraints. They > > looked like that: > > > > CONSTRAINT FK_users_countries > > FOREIGN KEY FK_users_countries (country_id) > > REFERENCES countries(country_id) > > ON DELETE RESTRICT > > ON UPDATE RESTRICT > > > > Now I want to use migration features so I used > > > > rake db:schema:dump > > > > When I look at the schema.rb file i don''t like what i see ;(. All the > > tables are there but the are no primary keys and also there are no > > Foreign Keys. > > > > My question is can i use the ruby way to create foreign keys? And why > > > > rake db:schema:dump > > > > doesn''t work? > > > > Nikola > > > > >-- Weverton Gomes de Morais Tecnólogo em Redes de Comunicação Desenvolvedor Delphi --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---