Module: Mongoid::Criterion::Modifiable
- Included in:
- Mongoid::Criteria
- Defined in:
- lib/mongoid/criterion/modifiable.rb
Instance Method Summary collapse
-
#build(attrs = {}, &block) ⇒ Document
(also: #new)
Build a document given the selector and return it.
-
#create(attrs = {}, &block) ⇒ Document
Create a document in the database given the selector and return it.
-
#create!(attrs = {}, &block) ⇒ Document
Create a document in the database given the selector and return it.
-
#find_or_create_by(attrs = {}, &block) ⇒ Document
Find the first
Document
given the conditions, or creates a new document with the conditions that were supplied. -
#find_or_initialize_by(attrs = {}, &block) ⇒ Document
Find the first
Document
given the conditions, or initializes a new document with the conditions that were supplied. -
#first_or_create(attrs = nil, &block) ⇒ Document
Find the first
Document
, or creates a new document with the conditions that were supplied plus attributes. -
#first_or_create!(attrs = nil, &block) ⇒ Document
Find the first
Document
, or creates a new document with the conditions that were supplied plus attributes and will raise an error if validation fails. -
#first_or_initialize(attrs = nil, &block) ⇒ Document
Find the first
Document
, or initializes a new document with the conditions that were supplied plus attributes.
Instance Method Details
#build(attrs = {}, &block) ⇒ Document Also known as: new
Build a document given the selector and return it. Complex criteria, such as $in and $or operations will get ignored.
18 19 20 |
# File 'lib/mongoid/criterion/modifiable.rb', line 18 def build(attrs = {}, &block) create_document(:new, attrs, &block) end |
#create(attrs = {}, &block) ⇒ Document
Create a document in the database given the selector and return it. Complex criteria, such as $in and $or operations will get ignored.
35 36 37 |
# File 'lib/mongoid/criterion/modifiable.rb', line 35 def create(attrs = {}, &block) create_document(:create, attrs, &block) end |
#create!(attrs = {}, &block) ⇒ Document
Create a document in the database given the selector and return it. Complex criteria, such as $in and $or operations will get ignored. If validation fails, an error will be raised.
54 55 56 |
# File 'lib/mongoid/criterion/modifiable.rb', line 54 def create!(attrs = {}, &block) create_document(:create!, attrs, &block) end |
#find_or_create_by(attrs = {}, &block) ⇒ Document
Find the first Document
given the conditions, or creates a new document with the conditions that were supplied.
67 68 69 |
# File 'lib/mongoid/criterion/modifiable.rb', line 67 def find_or_create_by(attrs = {}, &block) find_or(:create, attrs, &block) end |
#find_or_initialize_by(attrs = {}, &block) ⇒ Document
Find the first Document
given the conditions, or initializes a new document with the conditions that were supplied.
80 81 82 |
# File 'lib/mongoid/criterion/modifiable.rb', line 80 def find_or_initialize_by(attrs = {}, &block) find_or(:new, attrs, &block) end |
#first_or_create(attrs = nil, &block) ⇒ Document
Find the first Document
, or creates a new document with the conditions that were supplied plus attributes.
95 96 97 |
# File 'lib/mongoid/criterion/modifiable.rb', line 95 def first_or_create(attrs = nil, &block) first_or(:create, attrs, &block) end |
#first_or_create!(attrs = nil, &block) ⇒ Document
Find the first Document
, or creates a new document with the conditions that were supplied plus attributes and will raise an error if validation fails.
111 112 113 |
# File 'lib/mongoid/criterion/modifiable.rb', line 111 def first_or_create!(attrs = nil, &block) first_or(:create!, attrs, &block) end |
#first_or_initialize(attrs = nil, &block) ⇒ Document
Find the first Document
, or initializes a new document with the conditions that were supplied plus attributes.
126 127 128 |
# File 'lib/mongoid/criterion/modifiable.rb', line 126 def first_or_initialize(attrs = nil, &block) first_or(:new, attrs, &block) end |