Rails doesn''t support composite primary keys (at the moment).  if
you''re
doing new development, just use an ''id'' column as your primary
key.
On 1/11/06, Hugo Wetterberg <hugo.wetterberg@gmail.com>
wrote:>
> Hi All,
> How do I specify a composite primary key for a table in ActiveRecord?
> For example the table Recipe which has the primary key [cookie id, version
> number] where cookie id is also a foreign key referencing Cookie.
>
> Also: Thanks to Nic and Adam for helping with the Cookie -> Cooky
problem.
>
> /Hugo
>
> --SQL
> *
> CREATE* *TABLE* `Raw_Materials`*
> (*
>        id                       *INT* AUTO_INCREMENT*,*
>        `name `          *VARCHAR**(* 30*),*
>        quantity                *INT** ,*
>        lastDelivery    DATETIME*,*
>        * PRIMARY* *KEY* *(*id*)* *
> );*
>
> *CREATE* * TABLE* `Cookies `
> *(*
>        id                      *INT* AUTO_INCREMENT*,*
>        ` name`          *VARCHAR** (*30*),*
>        *primary* * key* *(* id*)*
> *);*
>
> *CREATE* * TABLE* `Recipes `
> *(*
>        ` version`               *INT** ,*
>        cookie_id               *INT** ,*
>        * PRIMARY* *KEY* *(*version*,* cookie_id*),*
>        * FOREIGN* *KEY* *(*cookie_id*)* *REFERENCES* Cookies*(*id*)*
> *);*
>
> *CREATE* * TABLE* `Ingredients `
> *(*
>        ` version`                       *INT **,*
>        cookie_id                       *INT **,*
>        raw_material_id *INT** ,*
>        quantity                         *INT**, *
>        *PRIMARY* *KEY* * (*version*,* cookie_id*,* raw_material_id*),*
>        *FOREIGN* * KEY* *(* version*,* cookie_id*)* *REFERENCES* Recipes*(
> *version*,* cookie_id*),*
>        *FOREIGN* * KEY* *(* raw_material_id*)* *REFERENCES* Raw_Materials*
> (*id*)*
> * );*
>
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060111/9fab9a15/attachment-0001.html