Jaromír Červenka


60 Experience
0 Lessons Completed
0 Questions Solved


Would you move (to the Domain model) the validation only or whole logic of role as well (and keep only the access_rights here)? Having something like:

domain.owner_id # => User
domain.payer_id # => User

But isn't it redundant then? I'd have to ask two places for complete picture, right?


this question is more conceptual, than technical one. Do you think that it's a good idea to handle different types of "access rights" and "roles" in third model like this?

class DomainOwnership < ApplicationRecord
  belongs_to :domain
  belongs_to :user

  enum access_rights: [:ro, :rw]
  enum role: [:no_role, :owner, :payer]

  validates :role, uniqueness: { scope: :domain }, if: :owner_or_payer?

  def owner_or_payer?

The role validation is what I am concerned about. What I'd like to achieve is to have only one owner and/or payer per Domain. Should it be here or in Domain model?

Thank you :o)

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2021 GoRails, LLC. All rights reserved.