Method: M4DBI::Model.one_to_many
- Defined in:
- lib/m4dbi/model.rb
.one_to_many(the_one, the_many, many_as, one_as, the_one_fk) ⇒ Object
299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/m4dbi/model.rb', line 299 def self.one_to_many( the_one, the_many, many_as, one_as, the_one_fk ) the_one.class_def( many_as.to_sym ) do M4DBI::Collection.new( self, the_many, the_one_fk ) end the_many.class_def( one_as.to_sym ) do the_one[ @row[ the_one_fk ] ] end the_many.class_def( "#{one_as}=".to_sym ) do |new_one| send( "#{the_one_fk}=".to_sym, new_one.pk ) end end |