Class: StaticModel::Associations::HasManyAssociation

Inherits:
Association
  • Object
show all
Defined in:
lib/static_model/associations.rb

Instance Attribute Summary

Attributes inherited from Association

#foreign_key, #klass, #name, #options

Instance Method Summary collapse

Methods inherited from Association

#initialize, #reflection_klass

Constructor Details

This class inherits a constructor from StaticModel::Associations::Association

Instance Method Details

#define_association_methodsObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/static_model/associations.rb', line 53

def define_association_methods
  if reflection_klass.respond_to?(:scoped)
    klass.module_eval "      def \#{name}\n        \#{reflection_klass}.scoped(:conditions => {:\#{foreign_key} => id})\n      end\n    EOT\n  else\n    klass.module_eval <<-EOT\n    def \#{name}\n      \#{reflection_klass}.send(:find_all_by_\#{foreign_key}, id)\n    end\n    EOT\n  end\nend\n"