Namespaced key lookup on Rails 5 association with ActiveRecord -
i have following models:
class supervision::applicationrecord < activerecord::base self.abstract_class = true def self.table_name_prefix "supervision_" end end --------------- class supervision::activity < supervision::applicationrecord has_one :supervision_missed_visit, class_name: supervision::missedvisit (...) end --------------- class supervision::missedvisit < supervision::applicationrecord belongs_to :supervision_activity, class_name: supervision::activity (...) end
and have model, isn't namespaced:
class activity < applicationrecord (...) end
whenever try reach supervision::missedvisit
through has_one
relationship, in
@supervision_activity.supervision_missed_visit
i following error:
error: column supervision_missed_visits.activity_id not exist
how make rails understands i'm looking supervision_missed_visits.supervision_activity_id
?
you specify foreign key:
has_one :supervision_missed_visit, class_name: supervision::missedvisit, foreign_key: 'supervision_activity_id'
another way create instance method in supervision::activity
:
def missed_visit supervision::missedvisit.where(supervision_activity_id: id).take end
Comments
Post a Comment