ruby on rails 3.2 - Complex model relationships compared to writing methods -


i adding voting , karma/reputation system (similar here, hn, etc.) app , have decided make own none of existing gems had features wanted. while working on basic functionality ended writing pretty complex associations in models, , unsure how compares say, writing own methods (or scopes) return same data.

pseudo-code below. (users can vote on questions , answers, users have upvotes , downvotes through q/a they've posted)

user   has_many :questions   has_many :answers   has_many :votes    has_many :question_up_votes, through: :questions, source: :vote,              conditions: {voteable_type: :question, 'score > 0'}    has_many :question_down_votes, through: :questions, source: :vote,              conditions: {voteable_type: :question, 'score < 0'}    has_many :answer_up_votes, through: :answers, source: :vote,              conditions: {voteable_type: :answer, 'score > 0'}    has_many :answer_down_votes, through: :answers, source: :vote,              conditions: {voteable_type: :answer, 'score < 0'}   question   belongs_to :user   has_many :questions   has_many :votes, as: :voteable   answer   belongs_to :user   belongs_to :question   has_many :votes, as: :voteable   vote   belongs_to :voter, class_name: "user"   belongs_to :voteable, polymorphic: true   belongs_to :user, through: :voteable    attr_accessible :score, :user_id, :voteable_type, :voteable_id 

specifically, 4 complex associations in user model, better performance, less error-prone, or have other advantages write methods (or scopes) return same information, either in user model or q/a models?

i'm new rails (and programming) , first stack overflow question, gentleness appreciated. let me know if question better fit different stack property. thanks!


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -