Method: Dock::Sequel#create
- Defined in:
- lib/dock/adapters/sequel.rb
#create ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/dock/adapters/sequel.rb', line 5 def create() associated_objects = [] attrs = {} model.db.transaction do attributes.each do |col, value| if model.associations.include?(col) Array(value).each{|v| associated_objects << [association_method(col), v]} else attrs.merge!(col => value) # pass it on end end obj = model.create(attrs) # create main obj associated_objects.each do |m,o| obj.send(m, o) end obj.save end # transaction end |