Sha256: 38036b4d7a3d50395647067628b84bc74e4514c94e0172e728009ffc85bf366a
Contents?: true
Size: 1.28 KB
Versions: 4
Compression:
Stored size: 1.28 KB
Contents
module ActiveForce module Association class Association extend Forwardable def_delegators :relation_model, :build attr_accessor :options, :relation_name def initialize parent, relation_name, options = {} @parent = parent @relation_name = relation_name @options = options define_relation_method end def relation_model options[:model] || relation_name.to_s.singularize.camelcase.constantize end def foreign_key options[:foreign_key] || default_foreign_key end def relationship_name options[:relationship_name] || relation_model.table_name end ### # Does this association's relation_model represent # +sfdc_table_name+? Examples of +sfdc_table_name+ # could be 'Quota__r' or 'Account'. def represents_sfdc_table?(sfdc_table_name) name = sfdc_table_name.sub(/__r\z/, '').singularize relationship_name.sub(/__c\z|__r\z/, '') == name end def sfdc_association_field relationship_name.gsub /__c\z/, '__r' end private def infer_foreign_key_from_model(model) name = model.custom_table? ? model.name : model.table_name name.foreign_key.to_sym end end end end
Version data entries
4 entries across 4 versions & 2 rubygems