Module: Associatable
- Included in:
- SQLObject
- Defined in:
- lib/opal_orm/associatable.rb
Instance Method Summary collapse
- #assoc_options ⇒ Object
- #belongs_to(name, options = {}) ⇒ Object
- #has_many(name, options = {}) ⇒ Object
- #has_one_through(name, through_name, source_name) ⇒ Object
Instance Method Details
#assoc_options ⇒ Object
56 57 58 |
# File 'lib/opal_orm/associatable.rb', line 56 def @assoc_options ||= {} end |
#belongs_to(name, options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/opal_orm/associatable.rb', line 37 def belongs_to(name, = {}) [name] = BelongsToOptions.new(name,) define_method(name) do # p "within class" # p @assoc_options = BelongsToOptions.new(name,options) opts = self.class.[name] opts.model_class.find(self.send("#{opts.foreign_key}")) end end |
#has_many(name, options = {}) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/opal_orm/associatable.rb', line 48 def has_many(name, = {}) define_method(name) do @options = HasManyOptions.new(name,self.class.to_s,) # TODO: why is this here? # cats = @options.model_class.where(@options.foreign_key => id) end end |
#has_one_through(name, through_name, source_name) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/opal_orm/associatable.rb', line 60 def has_one_through(name, through_name, source_name) define_method(name) do = self.class.[through_name] = .model_class.[source_name] through = .model_class .where(.primary_key => id) .first .model_class.find(through.id) end end |