开发者

Rails User Rating Another User

I am working on an application where a user has the ability to leave feedback on another user. Currently, I already have an implemented u开发者_如何学运维ser model.

Is this considered a self referential association?

This seems a bit wierd to me (how to set it up through Active Record Associations).

How would I go about setting this association up, what type of association is it? Anything I need to watch out for while going about this (tips, suggestions, errors that may come up)?

According to Answers Below Would This be the Way?

(one to many between users and ratings and one to one between ratings and user)

class User < ActiveRecord::Base
    has_many :ratings
end

class Ratings < ActiveRecord::Base
    belongs_to :user
end


This may not be in Rails/Active Record terms but ORM generic.

I would probably implement this by having a Feedback or Review model and your User model would have one-to-many Feedback/Reviews and the Feedback/Review would have a one-to-one relationship with the User who created it.

EDIT: Response to question update...

You can have an User object on the Ratings model that is the author. My rails experience is minimal but I believe your Ratings model would look like this.

class Ratings < ActiveRecord::Base
    belongs_to :user
    has_one :user
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜