On Jun 15, 4:31 pm, doug <[email protected]> wrote:
> In the blog screencast the commentator creates two model classes,
> 'Post' and 'Comment'. Note that both of these model classes are
> singular. However, when he creates the association he says in the
> Post model 'has_many(:comments)'. IOW, he uses the plural form of the
> Comment model and lowers the case of the the model class name.
> However, when he does the association within the Comment class he says
> 'belongs_to(:post)'. Here he does not pluralize post although he does
> (as expected) lower the case. This perplexes me.
comments is pluralized because a post has many comments (1:n
association)
post is singular because a comment belongs to a single post, not
several.
>
> Now, I want to follow this example; but, I want my model classes to be
> named 'BlogPost' and 'BlogComment' respectively in order to avoid
> potential namespace conflicts. I am not getting my associations to
> work. I think that I may be having trouble with the naming. In the
> BlogPost class do I say, 'has_many(:blogComments)' and in the
> BlogComment class say, 'belongs_to(:blogPost)'? This pluralizing
> thing is really confusing me. Additionally, I'm beginning to wonder
> if I don't need to introduce some underscores, e.g., 'blog_comment' or
> 'blog_comments'. Anyway, I'm obviously very confused. Can someome
> please straighten me out on exactly how these associations should be
> formed?
underscored: blog_comments; blog_post
Fred
>
> Thanks for any input.
>
> ... doug
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---