On 6 March 2011 15:17, mohamed mosaad <[email protected]> wrote: > Hi > I am not sure how foreign keys work here, i used belongs_to and > has_many and created an extra attribute for the foreign key my > question is how can i say this is the foreign key
Assuming that you follow the Rails conventions then you do not need to, so if you have Foo belongs to bar and Bar has many foos, then Rails will expect the foos table to have a column bar_id as the foreign key. However you may like to look at the foreigner gem which allows foreign key constraints to be applied to the database to prevent invalid foreign keys being saved. If you are just starting then it is not necessary to do this for the moment. I recommend it for production however. I suggest running through some guides and tutorials which will help you to understand how all this works. railstutorial.org is a good free online tutorial and you should look at the Rails Guides also. Colin -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

