私は協会に精通しておらず、このセクションに関する幅広い知識を持っていません。
以下は私のユースケースです:
2つのモデルがあります:
->従業員(チームリーダーとして)は、チームメンバー(従業員)に評価を与えることができます
has_many
関係だけを取るのは良い考えemployee to rating
ですか?また、Team Lead
ログインセッションでチームリーダーの評価とチームメンバーの評価を別々に表示する方法について、少し混乱しています。
助けてください。
ratings
テーブルは持つべきgiver_id
とemployee_id
列を。次に:
class Employee < ActiveRecord::Base
has_many :given_ratings, foreign_key: :giver_id, class_name: Rating
has_many :ratings
end
class Rating < ActiveRecord::Base
belongs_to :giver, class_name: Employee
belongs_to :employee
end
次に、どの従業員にとっても、次のことが機能するはずです。
team_lead = # fetch employee however
team_lead.ratings # ratings given TO this employee
team_lead.given_ratings # ratings given BY this employee
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加