i'm working on building simple rails application (this first rails project) tracking statistics users within group. i've created tables using migration script , looks alright when @ in mysql, not of models return data when join them table.
does see wrong models, migration script, or data model?
here migration file script code:
class creategroupsusers < activerecord::migration def change create_table :types |t| t.string :name end create_table :groups |t| t.string :name t.belongs_to :type, index: true end create_table :users |t| t.string :username t.string :email t.string :first_name t.string :last_name t.string :e_password t.string :salt t.timestamps end create_table :roles |t| t.string :name end create_table :groups_users, id: false |t| t.belongs_to :group, index: true t.belongs_to :user, index: true t.belongs_to :role, index: true end create_table :statistics |t| t.string :name end create_table :groups_users_statistics, id: false |t| t.string :value t.belongs_to :group, index: true t.belongs_to :user, index: true t.belongs_to :statistic, index: true end end end
here my models:
class type < activerecord::base has_many :groups end class role < activerecord::base has_many :groups_users end class user < activerecord::base has_and_belongs_to_many :groups has_one :roles, through: :groups_users end class group < activerecord::base has_and_belongs_to_many :users has_one :types end class statistic < activerecord::base //i'm not sure how define model end
and here's data model
i updated models per esse, pavan , andyv's comments. seems working fine now
class type < activerecord::base has_many :groups end class role < activerecord::base has_many :group_users end class user < activerecord::base has_many :group_users has_many :groups, through: :group_users has_many :group_user_statistics has_many :groups, through: :group_user_statistics has_many :statistics, through: :group_user_statistics end class group < activerecord::base has_many :group_users has_many :users, through: :group_users has_many :group_user_statistics has_many :users, through: :group_user_statistics has_many :statistics, through: :group_user_statistics end class groupuser < activerecord::base belongs_to :group belongs_to :user end class statistic < activerecord::base has_many :group_user_statistics has_many :groups, through: :group_user_statistics has_many :users, through: :group_user_statistics end class groupuserstatistic < activerecord::base belongs_to :user belongs_to :group belongs_to :statistic end
Comments
Post a Comment