At the moment, it looks a user doesn't actually have many preps in the Rails sense (as in: based on user_id on a prep). And I don't see a belongs_to :user on Prep, but rather two relationships to users.
It might make sense to remove has_many :preps on User and go with something like this instead:
def athleted_preps
Prep.where(athlete: self)
end
def coached_preps
Prep.where(coach: self)
end
def preps
athleted_preps.or(coached_preps)
end
This would then allow you to simplify in a bunch of other areas. prep_includes_user?(user) for instance.
def prep_includes_user?(user)
current_user.coached_preps.where(athlete: user).any?
end
https://github.com/SherSpock/muscle-wizards/blob/master/app/models/user.rb#L6
At the moment, it looks a user doesn't actually have many preps in the Rails sense (as in: based on
user_id
on a prep). And I don't see abelongs_to :user
onPrep
, but rather two relationships to users.It might make sense to remove
has_many :preps
on User and go with something like this instead:This would then allow you to simplify in a bunch of other areas.
prep_includes_user?(user)
for instance.Bonus: this is now all done through SQL.