On Sun, Mar 6, 2011 at 4:17 PM, mohamed mosaad <[email protected]> wrote:

> 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

If the schema follows AR naming conventions the FK is inferred.

For example, if post has many comments

    has_many :comments, :dependent => :destroy

and a comment belongs to a post

    belongs_to :post

and the FK in the comments table is called post_id, you're done. AR
will figure it out.

If the column is called something else there's an option to specify
which is the FK, but if you're defining a new schema it is better (and
expected) to just follow the conventions.

-- 
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.

Reply via email to