Module: Rkid::FastCreate
Instance Method Summary collapse
Instance Method Details
#create(attributes) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/rkid/models.rb', line 7 def create(attributes) insert = db.prepare " INSERT INTO \#{table_name}\n (\#{attributes.keys.join(', ')}) VALUES (\#{attributes.keys.collect { |c| \":\#{c}\" }.join(', ')})\n SQL\n insert.execute attributes\n instantiate(attributes.merge('id' => db.last_insert_row_id))\nend\n" |
#db ⇒ Object
3 4 5 |
# File 'lib/rkid/models.rb', line 3 def db ActiveRecord::Base.connection.raw_connection end |