Method: Sequel::Model::ClassMethods#db
- Defined in:
- lib/sequel/model/base.rb
#db ⇒ Object
Returns the database associated with the Model class. If this model doesn’t have a database associated with it, assumes the superclass’s database, or the first object in Sequel::DATABASES. If no Sequel::Database object has been created, raises an error.
Artist.db.transaction do # BEGIN
Artist.create(name: 'Bob')
# INSERT INTO artists (name) VALUES ('Bob')
end # COMMIT
352 353 354 355 356 357 |
# File 'lib/sequel/model/base.rb', line 352 def db return @db if @db @db = self == Model ? Sequel.synchronize{DATABASES.first} : superclass.db raise(Error, "No database associated with #{self}: have you called Sequel.connect or #{self}.db= ?") unless @db @db end |