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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -