Module: DelegateBelongsTo::ClassMethods

Defined in:
lib/spree/core/delegate_belongs_to.rb

Constant Summary collapse

@@default_rejected_delegate_columns =
['created_at','created_on','updated_at','updated_on','lock_version','type','id','position','parent_id','lft','rgt']

Instance Method Summary collapse

Instance Method Details

#delegate_belongs_to(association, *attrs) ⇒ Object

TODO:

Integrate this with ActiveRecord::Dirty, so if you set a property through one of these setters and then call save on this object, it will save the associated object automatically.

Creates methods for accessing and setting attributes on an association. Uses same default list of attributes as delegates_to_association. delegate_belongs_to :contact delegate_belongs_to :contact, [:defaults] ## same as above, and useless delegate_belongs_to :contact, [:defaults, :address, :fullname], class_name: ‘VCard’



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/spree/core/delegate_belongs_to.rb', line 34

def delegate_belongs_to(association, *attrs)
  ActiveSupport::Deprecation.warn("    DelegateBelongsTo module is deprecated and will be removed in Spree 3.4\n  EOS\n\n  opts = attrs.extract_options!\n  initialize_association :belongs_to, association, opts\n  attrs = get_association_column_names(association) if attrs.empty?\n  attrs.concat get_association_column_names(association) if attrs.delete :defaults\n  attrs.each do |attr|\n    class_def attr do |*args|\n      send(:delegator_for, association, attr, *args)\n    end\n\n    class_def \"\#{attr}=\" do |val|\n      send(:delegator_for_setter, association, attr, val)\n    end\n  end\nend\n", caller)