is there anyone who knows that? i have searched the web and api,but not found. :( thanks. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Apr-09 14:56 UTC
Re: how to set up multiple primary key in the rails migrate?
On 9 Apr 2008, at 15:55, Vincent.Z wrote:> > is there anyone who knows that? > i have searched the web and api,but not found. :( > thanks.Isn''t a primary key unique by definition ? Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Vincent.Z
2008-Apr-09 15:05 UTC
Re: how to set up multiple primary key in the rails migrate?
i means primary_key(:tag_id,:book_id).like this. maybe combination primary key is more clear than "multiple". On Apr 9, 10:56 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 9 Apr 2008, at 15:55, Vincent.Z wrote: > > > > > is there anyone who knows that? > > i have searched the web and api,but not found. :( > > thanks. > > Isn''t a primary key unique by definition ? > > Fred--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
James Byrne
2008-Apr-09 15:08 UTC
Re: how to set up multiple primary key in the rails migrate?
Vincent.Z wrote:> i means primary_key(:tag_id,:book_id).like this. > > maybe combination primary key is more clear than "multiple". > > On Apr 9, 10:56�pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>This is called a composite primary key and there are plugins/gems to handle this. Search for composite_primary_key and Dr. Nic. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
James Byrne
2008-Apr-09 15:26 UTC
Re: how to set up multiple primary key in the rails migrate?
James Byrne wrote:> Vincent.Z wrote: >> i means primary_key(:tag_id,:book_id).like this.On reflection, it seems that I may have misunderstood your real question. A composite key is often called a natural key and it reflects the contents of the relation in the table. So, for example, if you have a translation model then your "natural key" might be language_code, source_text) and the dependent attribute would be translated_text. If what you are really asking for is how to set up a uniqueness constraint on multiple attributes then you can enforce this at the DB level by adding a unique composite index to the migration: add_index :books, :title, :edition, :publisher, :name => :idxU_books_edition, :unique => true Which creates a unique index on the title, edition and publisher attributes of the model books. To catch this inside rails before the DB gives an error you will need to add a validates_uniqueness_of or custom validation in the books model. Note as well that index implementations are all DBMS dependent and that creating an index does not necessarily provide any improvement in retrievals. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---