Changelog History
Page 5
-
v3.0.8
-
v3.0.6 Changes
Resolved Issues
#2375 Uniqueness validation scoping now works with aliased fields.
#2372 Ensure that all atomic operations mongoize values before executing.
#2370 Paranoid documents now properly don't get deleted when using
dependent: :restrictand an exception is raised.#2365 Don't do anything when trying to replace an embeds_one with the same document.
#2362 Don't store inverse of field values in the database when they are not needed. (When there is not more than one polymorphic parent defined on the same class).
#2360 Cloning documents should ignore mass assignment protection rules.
#2356 When limiting fields returned in queries via
onlyensure that the limitation is scoped to the model.โก๏ธ #2353 Allow
update_attributeto properly handle aliased fields.#2348 Conversion of strings to times should raise an arugment error if the string is invalid. (Campbell Allen)
#2346 Ensure
belongs_torelations are evolvable when passed the proxy and not the document.๐ #2334 Fixed aggregation map/reduce when fields sometimes do not exist. (James McKinney)
๐ #2330 Fixed inconsistency of #size and #length on criteria when the documents have been iterated over with a limit applied.
#2328 Ensure ordering is applied on all relation criteria if defined.
#2327 Don't execute callbacks from base document if the document cannot execute them.
#2318 Ensure setting any numeric on a Float field actually sets it as a float, even if the number provided is an integer.
-
v3.0.5 Changes
Resolved Issues
๐ #2313 Fixed deserialization of
nilTimeWithZonefields. (nagachika)#2311
Document#changesno longer returnsnilvalues for Array and Hash fields that were only accessed and didn't actually change. Regression from 2.4.x.#2310 Setting a many to many duplicate successively in memory no longer clears the inverse foreign keys.
#2309 Allow embeds_one relations to be set with hashes more than just the initial set.
#2308 Ensure documents retrieved via
#findonhas_manyandhas_and_belongs_to_manyrelations are kept in memory.๐ #2304 Default scopes now properly merge instead of overwrite when more than one is defined as per expectations with AR. (Kirill Maksimov)
#2300 Ensure reloading refreshes the document in the identity map.
#2298 Protect against many to many relations pulling a null set of ids. (Jonathan Hyman)
โก๏ธ #2291 Fixed touch operations only to update the timestamp and the optional field, no matter what the other changes on the document are.
#1091 Allow presence validation to pass if the value is
false.
-
v3.0.4 Changes
Resolved Issues
๐ #2280 Fix synchronization of many-to-many relations when an ordering default scope exists on either side of the association.
โก๏ธ #2278
Criteria#updatenow properly updates only the first matching document, whereCriteria#update_allwill update all matching documents. (no flag vs multi).#2274 When loading models, warn if error is raised but continue processing.
0๏ธโฃ #2272 Don't wipe selectors or options when removing the default scope for actual nil values. Must check if key exists as well.
โช #2266 Restored paranoid documents are no longer flagged as destroyed. (Mario Uher)
#2263 Ensure casting of non object id foreign keys on many to many relations happens in the initial set, not at validation time.
-
v3.0.3 Changes
Resolved Issues
#2259 Ensure subclassed documents can not be pulled from the identity map via an id of another document in the same collection with a parent or sibeling type.
#2254 $inc operations no longer convert all values to floats.
#2252 Don't fire autosave when before callbacks have terminated.
๐ #2248 Improved the performance of
exists?on criteria and relations. (Jonathan Hyman)
-
v3.0.2 Changes
Resolved Issues
โ #2244 Get rid of id mass assignment warnings in nested attributes.
#2242 Fix eager loading not to load all documents when calling first or last.
#2241 Map/reduce operations now always use strong consistency since they have the potential to write to collections, most of the time.
#2238 Ensure n-n foreign key fields are flagged as resizable to prevent
nil->[]changes when using#onlyand updating.๐ป #2236 Keep the instance of the document in the validations exception accessible via
documentorrecord.#2234 Ensure validations when document is getting persisted with custom options work properly with custom options, and do not clear them out if validation passes.
#2224
Model#incnow acceptsBigDecimalvalues.๐ #2216 Fixed assignment of metadata on embeds one relations when setting multiple times in a row.
#2212 Ensure errors are cleared after a save with
validate: falsein all situations.#2207 When eager loading ids the query must be duped to avoid multiple iteration problems not getting the required fields.
#2204 Raise an
InvalidIncludeserror when passing arguments toCriteria.includesthat are invalid (not relations, or more than 1 level.)#2203 Map/Reduce now works properly in conjunction with
Model#with.Band. with(session: "secondary"). where(:likes.gt => 100). map_reduce(map, reduce). out(inline: 1)#2199 Autosave false is now respected when automatically adding presence validation. (John Nishinaga)
-
v3.0.1 Changes
Resolved Issues
#2191 Ensure proper visibility (private) for error message generation methods.
#2187 Ensure all levels of nested documents are serialized in json.
๐ #2184 Allow names of relations that conflict with ruby core kernel methods to pass existence checks.
#2181 Ensure
.firstcriteria sort by ascending ids, if no other sorting criteria was provided.
-
v3.0.0 Changes
๐ New Features
๐ #2151 When asking for metadata before persistence, Mongoid will now raise a
Mongoid::Errors::NoMetadataerror if the metadata is not present.#2147
Model#becomesnow copies over the embedded documents.A new callback has been introduced:
upsert, which runs when callingdocument.upsertsince Mongoid does not know if the document is to be treated as new or persisted. With this come the model callbacks:before_upsert after_upsert around_upsert#2080/#2087 The database or session that Mongoid persists to can now be overridden on a global level for cases where
Model#withis not a viable option.Mongoid.override_database(:secondary) Mongoid.override_session(:secondary) Band.create(name: "Placebo") #=> Persists to secondary. band.albums.create #=> Persists to secondary.Note that this option is global and overrides for all models on the current thread. It is the developer's responsibility to remember to set this back to nil if you no longer want the override to happen.
Mongoid.override_database(nil) Mongoid.override_session(nil)#1989 Criteria
count,sizeandlengthnow behave as Active Record with regards to database access.Criteria#countwill always hit the database to get the count.Criteria#lengthandCriteria#sizewill hit the database once if the criteria has not been loaded, and subsequent calls will return the cached value.If the criteria has been iterated over or loaded,
lengthandsizewill never hit the db.#1976 Eager loading no longer produces queries when the base query returns zero results.
Model.find_bynow accepts a block and will yield to the found document if it is not nil.Band.find_by(name: "Depeche Mode") do |band| band.likes = 100 end๐ #1958/#1798 Documents and
belongs_torelations now support touch.class Band include Mongoid::Document include Mongoid::Timestamps::Updated belongs_to :label, touch: true endUpdate the document's updated_at timestamp to the current time. This will also update any touchable relation's timestamp as well.
Band.first.touchUpdate a specific time field along with the udpated_at.
Band.first.touch(:founded)This fires no validations or callbacks.
๐ Mongoid now supports MongoDB's $findAndModify command.
Band.find_and_modify("$inc" => { likes: 1 }) Band.desc(:name).only(:name).find_and_modify( { "$inc" => { likes: 1 }}, new: true )#1906 Mongoid will retrieve documents from the identity map when providing multiple ids to find. (Hans Hasselberg)
#1903 Mongoid raises an error if provided a javascript expression to a where clause on an embedded collection. (Sebastien Azimi)
Aggregations now adhere to both a Mongoid API and their enumerable counterparts where applicable.
Band.min(:likes) Band.min do |a, b| a.likes <=> b.likes end Band.max(:likes) Band.max do |a, b| a.likes <=> b.likes endNote that when providing a field name and no block, a single numeric value will be returned, but when providing a block, a document will be returned which has the min/max value. This is since Ruby's Enumerable API dictates when providing a block, the matching element is returned.
When providing a block, all documents will be loaded into memory. When providing a symbol, the execution is handled via map/reduce on the server.
A kitchen sink aggregation method is now provided, to get everything in in a single call for a field.
Band.aggregates(:likes) # => # { # "count" => 2.0, # "max" => 1000.0, # "min" => 500.0, # "sum" => 1500.0, # "avg" => 750.0 # }A DSL off the criteria API is now provided for map/reduce operations as a convenience.
Band.where(name: "Tool").map_reduce(map, reduce).out(inline: 1) Band.map_reduce(map, reduce).out(replace: "coll-name") Band.map_reduce(map, reduce).out(inline: 1).finalize(finalize)๐ Mongoid now uses Origin for its Criteria API. See the Origin repo and API docs for the documentation.
#1861 Mongoid now raises an
AmbiguousRelationshiperror when it cannot determine the inverse of a relation and there are multiple potential candidates. (Hans Hasselberg)You can now perform an explain directly from criteria.
Band.where(name: "Depeche Mode").explain#1856 Push on one to many relations can now be chained.
band.albums.push(undertow).push(aenima)๐ #1842 MultiParameterAttributes now supported aliased fields. (Anton Orel)
#1833 If an embedded document is attempted to be saved with no parent defined, Mongoid now will raise a
Mongoid::Errors::NoParentexception.โ Added an ORM-agnostic way to get the field names
class Band include Mongoid::Document field :name, type: String end Band.attribute_names#1831
find_or_create_byon relations now takes mass assignment and type options. (Tatsuya Ono)class Band include Mongoid::Document embeds_many :albums end band.albums.find_or_create_by({ name: "101" }, LP)#1818 Add capability to choose the key where your
embeds_manyrelation is stores. (Cyril Mougel)class User include Mongoid::Document field :name, type: String embeds_many :prefs, class_name: "Preference", store_as: 'my_preferences' end user.prefs.build(value: "ok") user.save # document saves in MongoDB as: # { "name" => "foo", "my_preferences" => [{ "value" => "ok" }]}#1806
Model.find_or_create_byandModel.find_or_initialize_bycan now take documents as paramters for belongs_to relations.person = Person.first Game.find_or_create_by(person: person)#1774 Relations now have a :restrict option for dependent relations which will raise an error when attempting to delete a parent that still has children on it. (Hans Hasselberg)
class Band include Mongoid::Document has_many :albums, dependent: :restrict end band = Band.first band.albums << Albums.first band.delete # Raises DeleteRestriction error.0๏ธโฃ #1764 Add method to check if field differs from the default value.
class Band include Mongoid::Document field :name, type: String, default: "New" end band = Band.first band.name_changed_from_default?โก๏ธ #1759 Invalid fields error messages have been updated to show the source and location of the original method. The new message is:
Problem: Defining a field named 'crazy_method' is not allowed. Summary: Defining this field would override the method 'crazy_method', which would cause issues with expectations around the original method and cause extremely hard to debug issues. The original method was defined in: Object: MyModule File: /path/to/my/module.rb Line: 8 Resolution: Use Mongoid.destructive_fields to see what names are not allowed, and don't use these names. These include names that also conflict with core Ruby methods on Object, Module, Enumerable, or included gems that inject methods into these or Mongoid internals.#1753/#1649 A setter and getter for has_many relations to set its children is now provided. (Piotr Jakubowski)
class Album include Mongoid::Document has_many :engineers end class Engineer include Mongoid::Document belongs_to :album end album = Album.first engineer = Engineer.first album.engineer_ids = [ engineer.id ] album.engineer_ids # Returns the ids of the engineers.๐ #1741 Mongoid now provides a rake task to force remove indexes for environments where Mongoid manages the index definitions and the removal should be automated. (Hans Hasselberg)
rake db:force_remove_indexes rake db:mongoid:force_remove_indexes#1726
Mongoid.load!now accepts an optional second argument for the environment to load. This takes precedence over any environment variable that is set if provided.Mongoid.load!("/path/to/mongoid.yml", :development)๐ #1724 Mongoid now supports regex fields.
class Rule include Mongoid::Document field :pattern, type: Regexp, default: /[^abc]/ end๐ฒ #1714/#1706 Added better logging on index creation. (Hans Hasselberg)
When an index is present on a root document model:
Creating indexes on: Model for: name, dob.When an index is defined on an embedded model:
Index ignored on: Address, please define in the root model.When no index is defined, nothing is logged, and if a bad index is defined an error is raised.
#1710 For cases when you don't want Mongoid to auto-protect the id and type attributes, you can set a configuration option to turn this off.
Mongoid.protect_sensitive_fields = false#1685 Belongs to relations now have build_ and create_ methods.
class Comment include Mongoid::Document belongs_to :user end comment = Comment.new comment.build_user # Build a new user object comment.create_user # Create a new user object#1684 Raise a
Mongoid::Errors::InverseNotFoundwhen attempting to set a child on a relation without the proper inverse_of definitions due to Mongoid not being able to determine it.class Car include Mongoid::Document embeds_one :engine, class_name: "Motor" end class Motor include Mongoid::Document embedded_in :machine, class_name: "Car" end car = Car.new car.engine = Motor.new # raises an InverseNotFound error.#1680 Polymorphic relations now use
*_typekeys in lookup queries.class User include Mongoid::Document has_many :comments, as: :commentable end class Comment include Mongoid::Document belongs_to :commentable, polymorphic: true end user = User.find(id) user.comments # Uses user.id and type "User" in the query.๐ #1677 Support for parent separable polymorphic relations to the same parent class is now available. This only works if set from the parent side in order to know which relation the children belong to. (Douwe Maan)
class Face include Mongoid::Document has_one :left_eye, class_name: "Eye", as: :visible has_one :right_eye, class_name: "Eye", as: :visible end class Eye include Mongoid::Document belongs_to :visible, polymorphic: true end face = Face.new right_eye = Eye.new left_eye = Eye.new face.right_eye = right_eye face.left_eye = left_eye right_eye.visible = face # Will raise an error.๐ #1650 Objects that respond to
to_criteriacan now be merged into existing criteria objects.class Filter def to_criteria # return a Criteria object. end end criteria = Person.where(title: "Sir") criteria.merge(filter)#1635 All exceptions now provide more comprehensive errors, including the problem that occurred, a detail summary of why it happened, and potential resolutions. Example:
(Mongoid::Errors::DocumentNotFound) Problem: Document not found for class Town with id(s) [BSON::ObjectId('4f35781b8ad54812e1000001')]. Summary: When calling Town.find with an id or array of ids, each parameter must match a document in the database or this error will be raised. Resolution: Search for an id that is in the database or set the Mongoid.raise_not_found_error configuration option to false, which will cause a nil to be returned instead of raising this error.#1616
Model.find_byadded which takes a hash of arguments to search for in the database. If no single document is returned a DocumentNotFound error is raised. (Piotr Jakubowski)Band.find_by(name: "Depeche Mode")#1606 Mongoid now enables autosave, like Active Record, when adding an accepts_nested_attributes_for to a relation.
class Band include Mongoid::Document has_many :albums accepts_nested_attributes_for :albums # This enables the autosave. end#1477 Mongoid now automatically protects the id and type attributes from mass assignment. You can override this (not recommended) by redefining them as accessible.
class Band include Mongoid::Document attr_accessible :id, :_id, :_type end#1459 The identity map can be disabled now for specific code execution by passing options to the unit of work.
Mongoid.unit_of_work(disable: :all) do # Disables the identity map on all threads for the block. end Mongoid.unit_of_work(disable: :current) do # Disables the identity map on the current thread for the block. end Mongoid.unit_of_work do # Business as usual. end#1355 Associations now can have safety options provided to them on single document persistence operations.
band.albums.with(safe: true).push(album) band.albums.with(safe: true).create(name: "Smiths") album.with(safe: true).create_producer(name: "Flood")๐ #1348 Eager loading is now supported on many-to-many relations.
๐ #1292 Remove attribute now unsets the attribute when the document is saved instead of setting to nil.
band = Band.find(id) band.remove_attribute(:label) # Uses $unset when the document is saved.#1291 Mongoid database sessions are now connected to lazily, and are completely thread safe. If a new thread is created, then a new database session will be created for it.
๐ #1291 Mongoid now supports any number of database connections as defined in the mongoid.yml. For example you could have a local single server db, a multi availability zone replica set, and a shard cluster all in the same application environment. Mongoid can connect to any session at any point in time.
#1291 Mongoid now allows you to persist to whatever database or collection you like at runtime, on a per-query or persistence operation basis by using
with.Band.with(collection: "artists").create(name: "Depeche Mode") band.with(database: "secondary).save! Band.with(collection: "artists").where(name: "Depeche Mode")๐ง #1291 You can now configure on a per-model basis where its documents are stored with the new and improved
store_inmacro.class Band include Mongoid::Document store_in collection: "artists", database: "secondary", session: "replica" endThis can be overridden, of course, at runtime via the
withmethod.#1212 Embedded documents can now be popped off a relation with persistence.
band.albums.pop # Pop 1 document and persist the removal. band.albums.pop(3) # Pop 3 documents and persist the removal.#1188 Relations now have existence predicates for simplified checking if the relation is blank or not. (Andy Morris)
class Band include Mongoid::Document embeds_many :albums embeds_one :label end band = Band.new band.albums? band.has_albums? band.label? band.has_label?#1188 1-1 relations now have an :autobuild option to indicate if the relation should automatically be build with empty attributes upon access where the relation currently does not exist. Works on embeds_one, embedded_in, has_one, belongs_to. (Andy Morris)
class Band include Mongoid::Document has_one :label, autobuild: true end band = Band.new band.label # Returns a new label with empty attributes.When using existence checks, autobuilding will not execute.
band = Band.new band.label? # Returns false, does not autobuild on a check. band.has_label? # Returns false, does not autobuild on a check.#1081 Mongoid indexes both id and type as a compound index when providing
index: trueto a polymorphic belongs_to.class Comment include Mongoid::Document # Indexes commentable_id and commentable_type as a compound index. belongs_to :commentable, polymorphic: true, index: true end#1053 Raise a
Mongoid::Errors::UnknownAttributeinstead of no method when attempting to set a field that is not defined and allow dynamic fields is false. (Cyril Mougel)Mongoid.allow_dynamic_fields = false class Person include Mongoid::Document field :title, type: String end Person.new.age = 50 # raises the UnknownAttribute error.#772 Fields can now be flagged as readonly, which will only let their values be set when the document is new.
class Band include Mongoid::Document field :name, type: String field :genre, type: String attr_readonly :name, :genre endReadonly values are ignored when attempting to set them on persisted documents, with the exception of update_attribute and remove_attribute, where errors will get raised.
band = Band.create(name: "Depeche Mode") band.update_attribute(:name, "Smiths") # Raises ReadonlyAttribute error. band.remove_attribute(:name) # Raises ReadonlyAttribute error.
Major Changes (Backwards Incompatible)
- Polymorphic relations can not have ids other than object ids. This is because Mongoid cannot properly figure out in an optimized way what the various classes on the other side of the relation store their ids as, as they could potentially all be different.
This was not allowed before, but nowhere was it explicitly stated.
#2039 Validating presence of a relation now checks both the relation and the foreign key value.
Indexing syntax has changed. The first parameter is now a hash of name/direction pairs with an optional second hash parameter for additional options.
Normal indexing with options, directions are either 1 or -1:
class Band include Mongoid::Document field :name, type: String index({ name: 1 }, { unique: true, background: true }) endGeospacial indexing needs "2d" as its direction.
class Venue include Mongoid::Document field :location, type: Array index location: "2d" endCustom serializable fields have revamped. Your object no longer should include
Mongoid::Fields::Serializable- instead it only needs to implement 3 methods:#mongoize,.demongoizeand.evolve.#mongoizeis an instance method that transforms your object into a mongo-friendly value..demongoizeis a class method, that can take some data from mongo and instantiate and object of your custom type..evolveis a class method, that can take any object, and transform it for use in aMongoid::Criteria.An example of an implementation of this for
Range:class Range def mongoize { "min" => first, "max" => last } end class << self def demongoize(object) Range.new(object["min"], object["max"]) end def evolve(object) { "$gte" => object.first, "$lte" => object.last } end end endDocument#changesis no longer a hash with indifferent access.after_initializecallbacks no longer cascade to children if the option is set.#1865
counton the memory and mongo contexts now behave exactly the same as Ruby'scounton enumerable, and can take an object or a block. This is optimized on the mongo context not to load everything in memory with the exception of passing a block.Band.where(name: "Tool").count Band.where(name: "Tool").count(tool) # redundant. Band.where(name: "Tool") do |doc| doc.likes > 0 endNote that although the signatures are the same for both the memory and mongo contexts, it's recommended you only use the block syntax for the memory context since the embedded documents are already loaded into memory.
Also note that passing a boolean to take skip and limit into account is no longer supported, as this is not necessarily a useful feature.
๐ง The
autocreate_indexesconfiguration option has been removed.0๏ธโฃ
Model.defaultsno longer exists. You may get all defaults with a combination ofModel.pre_processed_defaultsandModel.post_processed_defaults.Band.pre_processed_defaults Band.post_processed_defaults๐
Model.identityandModel.keyhave been removed. For custom ids, users must now override the _id field.When the default value is a proc, the default is applied after all other attributes are set.
class Band include Mongoid::Document field :_id, type: String, default: ->{ name } endTo have the default applied before other attributes, set
:pre_processedto true.class Band include Mongoid::Document field :_id, type: String, pre_processed: true, default: ->{ BSON::ObjectId.new.to_s } end๐ Custom application exceptions in various languages has been removed, along with the
Mongoid.add_languagefeature.๐ Mongoid no longer supports 1.8. MRI 1.9.3 and higher, or JRuby 1.6 and higher in 1.9 mode are only supported.
#1734 When searching for documents via
Model.findwith multiple ids, Mongoid will raise an error if not all ids are found, and tell you what the missing ones were. Previously the error only got raised if nothing was returned.#1675 Adding presence validation on a relation now enables autosave. This is to ensure that when a new parent object is saved with a new child and marked is valid, both are persisted to ensure a correct state in the database.
๐ #1491 Ensure empty translations returns an empty hash on access.
#1484
Model#has_attribute?now behaves the same as Active Record.#1471 Mongoid no longer strips any level of precision off of times.
0๏ธโฃ #1475 Active support's time zone is now used by default in time serialization if it is defined.
#1342
Model.findandmodel.relation.findnow only take a single or multiple ids. The first/last/all with a conditions hash has been removed.โฌ๏ธ #1291 The mongoid.yml has been revamped completely, and upgrading existing applications will greet you with some lovely Mongoid specific configuration errors. You can re-generate a new mongoid.yml via the existing rake task, which is commented to an insane degree to help you with all the configuration possibilities.
#1291 The
persist_in_safe_modeconfiguration option has been removed. You must now tell a database session in the mongoid.yml whether or not it should persist in safe mode by default.production: sessions: default: database: my_app_prod hosts: - db.app.com:27018 - db.app.com:27019 options: consistency: :eventual safe: true๐ #1291
safelyandunsafelyhave been removed. Please now usewithto provide safe mode options at runtime.Band.with(safe: true).create band.with(safe: { w: 3 }).save! Band.with(safe: false).create!#1270 Relation macros have been changed to match their AR counterparts: only :has_one, :has_many, :has_and_belongs_to_many, and :belongs_to exist now.
๐ #1268
Model#new?has been removed, developers must now always useModel#new_record?.#1182 A reload is no longer required to refresh a relation after setting the value of the foreign key field for it. Note this behaves exactly as Active Record.
If the id is set, but the document for it has not been persisted, accessing the relation will return empty results.
If the id is set and its document is persisted, accessing the relation will return the document.
If the id is set, but the base document is not saved afterwards, then reloading will return the document to its original state.
#1093 Field serialization strategies have changed on Array, Hash, Integer and Boolean to be more consistent and match AR where appropriate.
Serialization of arrays calls
Array.wrap(object)Serialization of hashes callsHash[object](to_hash on the object) Serialization of integers always returns an int viato_iSerialization of booleans defaults to false instead of nil.#933
:field.sizehas been renamed to:field.countin criteria for $size not to conflict with Symbol's size method.#829/#797 Mongoid scoping code has been completely rewritten, and now matches the Active Record API. With this backwards incompatible change, some methods have been removed or renamed.
Criteria#as_conditions and Criteria#fuse no longer exist.
Criteria#merge now only accepts another object that responds to
to_criteria.Criteria#merge! now merges in another object without creating a new criteria object.
Band.where(name: "Tool").merge!(criteria)Named scopes and default scopes no longer take hashes as parameters. From now on only criteria and procs wrapping criteria will be accepted, and an error will be raised if the arguments are incorrect.
class Band include Mongoid::Document default_scope ->{ where(active: true) } scope :inactive, where(active: false) scope :invalid, where: { valid: false } # This will raise an error. endThe 'named_scope' macro has been removed, from now on only use 'scope'.
Model.unscoped now accepts a block which will not allow default scoping to be applied for any calls inside the block.
Band.unscoped do Band.scoped.where(name: "Ministry") endModel.scoped now takes options that will be set directly on the criteria options hash.
Band.scoped(skip: 10, limit: 20)#463
Document#upsertis no longer aliased toDocument#saveand now actually performs a proper MongoDB upsert command when called. If you were using this method before and want the same behavior, please switch tosave.band = Band.new(name: "Tool") band.upsert #=> Inserts the document in the database. band.name = "Placebo" band.upsert #=> Updates the existing document.
Resolved Issues
#2166
Criteria#from_map_or_dbstrips type selection when eager loading since it will check if the type is correct after.๐ #2129 Fixed sorting for all fields on embeds many relations.
0๏ธโฃ #2124 Fixed default scope and deleted scope on paranoid documents.
#2122 Allow embedded documents to sort on boolean fields.
โก๏ธ #2119 Allow
Criteria#update_allto accept atomic ops and normal sets.#2118 Don't strip any precision during
DateTime->Timeconversions.#2117 Ensure embeds one relations have callbacks run when using nested attributes.
#2110
Model#touchnow works properly on embedded documents.#2100 Allow atomic operations to properly execute on paranoid documents that have a deleted_at set.
#2089 Allow proper separation of mongoization and evolving with respect to foreign keys.
#2088 Allow finds by string ids to pull from the identity map if the ids are stored as object ids.
#2085 Allow demongoization of floats and ints to big decimals.
๐ #2084 Don't cascade if metadata does not exist.
๐ฏ #2078 Calling
Model#cloneorModel#dupnow properly sets attributes as dirty.โก๏ธ #2070 Allow for updated_at to be overridden manually for new documents that also have a created_at.
#2041 Don't hit the database multiple times on relation access after an eager load returned zero documents.
#1997 Cascading callbacks should be able to halt the callback chain when terminating.
#1972
added,loaded, andunloadedcan now be valid scope names on a document that is part of a 1-n relation.#1952/#1950
#all_inbehavior on embedded documents now properly matches root documents when passing an empty array. (Hans Hasselberg)#1941/#1939
Model.find_bynow returns nil if raise not found error is set to false. (Hans Hasselberg)๐ #1859/#1860
Model#remove_attributenow properly unsets on embedded documents. (Anton Onyshchenko)#1852 Ensure no infinite recursion on cascading callbacks. (Ara Howard)
#1823
Relation#includes?now properly works with identity map enabled.#1810
Model#changed?no longer returns true when hash and array fields have only been accessed.#1876/#1782 Allow dot notation in embeds many criteria queries. (Cyril Mougel)
๐ #1745 Fixed batch clear to work within attribute setting.
#1718 Ensure consistency of #first/#last in relations - they now always match first/last in the database, but opts for in memory first.
โก๏ธ #1692/#1376
Model#updateattributesandModel#update_attributes!now accept assignment options. (Hans Hasselberg)#1688/#1207 Don't require namespacing when providing class name on relation macros inside the namespace. (Hans Hasselberg)
#1665/#1672 Expand complex criteria in nested criteria selectors, like #matches. (Hans Hasselberg)
#1335 Don't add id sorting criteria to first/last is there is already sorting options on the criteria.
#1321 Referenced many enumerable targets are now hash-backed, preventing duplicates in a more efficient manner.
#1135 DateTimes now properly get time zones on deserialization.
#1031 Mongoid now serializes values in Array fields to their proper Mongo-friendly values when possible.
#685 Attempting to use versioning with embedded documents will now raise a proper error alerting the developer this is not allowed.
-
v2.6.0 Changes
๐ New Features
- #2709 Backported the
touchfunctionality from Mongoid 3.
- #2709 Backported the
-
v2.5.2 Changes
Resolved Issues
- ๐ #2502 Fixed cache key to properly handle when the document does not
include
Mongoid::Timestamps::Updated. (Arthur Nogueira Neves)
- ๐ #2502 Fixed cache key to properly handle when the document does not
include