0

I am confuse on a concept. I am doing this on rails.

Is that Entity set equal to a table in the database?

Is that Relationship set equal to a table in the database?

Let say we have Entity set "USER" and Entity set "POST" and Entity set "COMMENT"

User- can post many posts and comments as they want
Post- belong to users
Comments-belong to posts ,users, so comment is weak entity.

SCHEMA
======
USER
-id
-name
POST
-id
-user_id(FK)
-comment_id (FK)
COMMENT
-id
-user_id (FK)
-post_id (FK)

so USER,POST,COMMENT are tables I think.

And what else is a table? And do I need a table for the relationship??

runcode
  • 3,533
  • 9
  • 35
  • 52
  • You should really read [the docs](http://guides.rubyonrails.org/association_basics.html). Sometimes you need a table for the relationship and sometimes you don't. It depends on how you declare the relationship in the model. – sosborn Oct 02 '12 at 03:31

2 Answers2

1

yes, they are tables but them should be always in a plural way. So you can have User, Post, Comment as models and Users, Posts, Comments as tables. And then yours models are related with their own tables

0

Given the data you do, start with the generators (add any additional needed fields, see rails generates model field:type, what are the options for field:type?):

rails generate model user name:string
rails generate model post user:references
rails generate model comment user:references post:references
Community
  • 1
  • 1
rewritten
  • 16,280
  • 2
  • 47
  • 50