mongoid 2.0.0.beta.15 → 2.0.0.beta.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/config/locales/en.yml +40 -0
- data/lib/config/locales/es.yml +41 -0
- data/lib/config/locales/fr.yml +42 -0
- data/lib/config/locales/it.yml +39 -0
- data/lib/config/locales/pl.yml +39 -0
- data/lib/config/locales/pt.yml +40 -0
- data/lib/config/locales/sv.yml +40 -0
- data/lib/mongoid.rb +7 -2
- data/lib/mongoid/associations.rb +16 -9
- data/lib/mongoid/associations/embedded_in.rb +11 -0
- data/lib/mongoid/associations/embeds_many.rb +28 -2
- data/lib/mongoid/associations/embeds_one.rb +18 -2
- data/lib/mongoid/associations/proxy.rb +28 -1
- data/lib/mongoid/associations/referenced_in.rb +10 -0
- data/lib/mongoid/associations/references_many.rb +10 -7
- data/lib/mongoid/associations/references_many_as_array.rb +29 -0
- data/lib/mongoid/associations/references_one.rb +9 -1
- data/lib/mongoid/attributes.rb +13 -3
- data/lib/mongoid/callbacks.rb +1 -0
- data/lib/mongoid/collections.rb +1 -1
- data/lib/mongoid/components.rb +1 -0
- data/lib/mongoid/config.rb +16 -1
- data/lib/mongoid/contexts/enumerable.rb +28 -1
- data/lib/mongoid/contexts/enumerable/sort.rb +43 -0
- data/lib/mongoid/contexts/mongo.rb +13 -1
- data/lib/mongoid/criteria.rb +4 -2
- data/lib/mongoid/criterion/inclusion.rb +22 -1
- data/lib/mongoid/criterion/optional.rb +14 -39
- data/lib/mongoid/criterion/selector.rb +65 -0
- data/lib/mongoid/document.rb +5 -11
- data/lib/mongoid/errors.rb +10 -130
- data/lib/mongoid/errors/document_not_found.rb +29 -0
- data/lib/mongoid/errors/invalid_collection.rb +19 -0
- data/lib/mongoid/errors/invalid_database.rb +20 -0
- data/lib/mongoid/errors/invalid_field.rb +19 -0
- data/lib/mongoid/errors/invalid_options.rb +16 -0
- data/lib/mongoid/errors/invalid_type.rb +26 -0
- data/lib/mongoid/errors/mongoid_error.rb +27 -0
- data/lib/mongoid/errors/too_many_nested_attribute_records.rb +21 -0
- data/lib/mongoid/errors/unsupported_version.rb +21 -0
- data/lib/mongoid/errors/validations.rb +22 -0
- data/lib/mongoid/extensions/hash/assimilation.rb +1 -1
- data/lib/mongoid/extensions/hash/criteria_helpers.rb +5 -3
- data/lib/mongoid/extensions/object/conversions.rb +5 -1
- data/lib/mongoid/extensions/objectid/conversions.rb +43 -1
- data/lib/mongoid/field.rb +13 -6
- data/lib/mongoid/finders.rb +1 -1
- data/lib/mongoid/hierarchy.rb +9 -4
- data/lib/mongoid/identity.rb +2 -2
- data/lib/mongoid/indexes.rb +1 -1
- data/lib/mongoid/matchers/default.rb +1 -1
- data/lib/mongoid/modifiers.rb +24 -0
- data/lib/mongoid/modifiers/command.rb +18 -0
- data/lib/mongoid/modifiers/inc.rb +24 -0
- data/lib/mongoid/persistence/command.rb +2 -10
- data/lib/mongoid/persistence/remove_all.rb +1 -1
- data/lib/mongoid/railtie.rb +2 -0
- data/lib/mongoid/railties/database.rake +102 -11
- data/lib/mongoid/railties/document.rb +12 -0
- data/lib/mongoid/safe.rb +13 -0
- data/lib/mongoid/safety.rb +12 -0
- data/lib/mongoid/validations.rb +0 -4
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid/versioning.rb +11 -1
- metadata +55 -28
- data/lib/mongoid/validations/locale/en.yml +0 -5
@@ -0,0 +1,40 @@
|
|
1
|
+
en:
|
2
|
+
activemodel:
|
3
|
+
errors:
|
4
|
+
messages:
|
5
|
+
taken: is already taken
|
6
|
+
|
7
|
+
mongoid:
|
8
|
+
errors:
|
9
|
+
messages:
|
10
|
+
document_not_found:
|
11
|
+
Document not found for class %{klass} with id(s) %{identifiers}.
|
12
|
+
invalid_database:
|
13
|
+
Database should be a Mongo::DB, not %{name}.
|
14
|
+
invalid_type:
|
15
|
+
Field was defined as a(n) %{klass}, but received a %{other} with
|
16
|
+
the value %{value}.
|
17
|
+
unsupported_version:
|
18
|
+
MongoDB %{version} not supported, please upgrade
|
19
|
+
to %{mongo_version}.
|
20
|
+
validations:
|
21
|
+
Validation failed - %{errors}.
|
22
|
+
invalid_collection:
|
23
|
+
Access to the collection for %{klass} is not allowed since it
|
24
|
+
is an embedded document, please access a collection from
|
25
|
+
the root document.
|
26
|
+
invalid_field:
|
27
|
+
Defining a field named %{name} is not allowed. Do not define
|
28
|
+
fields that conflict with Mongoid internal attributes or method
|
29
|
+
names. Use Document#instance_methods to see what names this includes.
|
30
|
+
too_many_nested_attribute_records:
|
31
|
+
Accepting nested attributes for %{association} is limited
|
32
|
+
to %{limit} records.
|
33
|
+
embedded_in_must_have_inverse_of:
|
34
|
+
Options for embedded_in association must include inverse_of.
|
35
|
+
dependent_only_references_one_or_many:
|
36
|
+
The dependent => destroy|delete option that was supplied
|
37
|
+
is only valid on references_one or references_many associations.
|
38
|
+
association_cant_have_inverse_of:
|
39
|
+
Defining an inverse_of on this association is not allowed. Only
|
40
|
+
use this option on embedded_in or references_many as array.
|
@@ -0,0 +1,41 @@
|
|
1
|
+
es:
|
2
|
+
activemodel:
|
3
|
+
errors:
|
4
|
+
messages:
|
5
|
+
taken: ya está en uso
|
6
|
+
|
7
|
+
mongoid:
|
8
|
+
errors:
|
9
|
+
messages:
|
10
|
+
document_not_found:
|
11
|
+
No se encontró ningún documento para la clase %{klass} con los id(s) %{identifiers}.
|
12
|
+
invalid_database:
|
13
|
+
La base de datos debería ser una instancia de Mongo::DB, en lugar de %{name}.
|
14
|
+
invalid_type:
|
15
|
+
El campo se definió como %{klass}, pero recibió una instancia de %{other}
|
16
|
+
con el valor %{value}.
|
17
|
+
unsupported_version:
|
18
|
+
MongoDB %{version} no está soportada, por favor actualize a
|
19
|
+
%{mongo_version}.
|
20
|
+
validations:
|
21
|
+
La validación falló - %{errors}.
|
22
|
+
invalid_collection:
|
23
|
+
El acceso a la colección %{klass} no está permitido, ya que
|
24
|
+
es un documento incrustado, por favor acceda a la colección
|
25
|
+
desde el documento raíz.
|
26
|
+
invalid_field:
|
27
|
+
No está permitido definir un campo con el nombre %{name}. No
|
28
|
+
defina campos que entren en conflicto con los atributos internos o
|
29
|
+
nombres de métodos de Mongoid. Utilice Document#instance_methods para
|
30
|
+
consultar los nombres ya incluidos.
|
31
|
+
too_many_nested_attribute_records:
|
32
|
+
La aceptación de atributos anidados para %{association} está limitada
|
33
|
+
a %{limit} registros.
|
34
|
+
embedded_in_must_have_inverse_of:
|
35
|
+
Las opciones de una asociación embedded_in deben incluir inverse_of.
|
36
|
+
dependent_only_references_one_or_many:
|
37
|
+
La opción dependent => destroy|delete proporcionada
|
38
|
+
sólo es válida en asociaciones references_one o references_many.
|
39
|
+
association_cant_have_inverse_of:
|
40
|
+
No está permitido definir inverse_of en esta asociación. Utilice
|
41
|
+
esta opción sólo en embedded_in o en references_many as array.
|
@@ -0,0 +1,42 @@
|
|
1
|
+
fr:
|
2
|
+
activemodel:
|
3
|
+
errors:
|
4
|
+
messages:
|
5
|
+
taken: est déjà pris.
|
6
|
+
|
7
|
+
mongoid:
|
8
|
+
errors:
|
9
|
+
messages:
|
10
|
+
document_not_found:
|
11
|
+
Document introuvable pour la classe %{klass} avec les ids %{identifiers}.
|
12
|
+
invalid_database:
|
13
|
+
La base de données doit être une Mongo::DB, pas %{name}.
|
14
|
+
invalid_type:
|
15
|
+
Le champ a été défini comme un(e) %{klass} mais a reçu un(e)
|
16
|
+
%{other} avec la valeur %{value}.
|
17
|
+
unsupported_version:
|
18
|
+
"MongoDB %{version} n'est pas supporté, veuillez mettre à jour avec
|
19
|
+
%{mongo_version}"
|
20
|
+
validations:
|
21
|
+
La validation a échouée - %{errors}.
|
22
|
+
invalid_collection:
|
23
|
+
"L'accès à la collection pour %{klass} n'est pas autorisé puisque
|
24
|
+
ce n'est pas un document embarqué, veuillez accéder à la collection
|
25
|
+
depuis le document racine."
|
26
|
+
invalid_field:
|
27
|
+
"Définir un champ appellé %{name} n'est pas autorisé. Veuillez ne
|
28
|
+
pas définir de champs en conflit avec les attributs internes de
|
29
|
+
Mongoid ou des noms de méthodes. Utilisez Document#instance_methods
|
30
|
+
pour consulter la liste des noms."
|
31
|
+
too_many_nested_attribute_records:
|
32
|
+
"Le nombre d'attributs imbriqués pour %{association} est limité à
|
33
|
+
%{limit} enregistrements."
|
34
|
+
embedded_in_must_have_inverse_of:
|
35
|
+
Les options pour les associations embedded_in doivent inclure
|
36
|
+
inverse_of.
|
37
|
+
dependent_only_references_one_or_many:
|
38
|
+
"L'option dependent => destroy|delete fournie est seulement valide
|
39
|
+
pour les associations references_on ou references_many."
|
40
|
+
association_cant_have_inverse_of:
|
41
|
+
"Definir un inverse_of pour cette association n'est pas autorisé.
|
42
|
+
Utilisez cette option seulement sur embedded_in ou references_many."
|
@@ -0,0 +1,39 @@
|
|
1
|
+
it:
|
2
|
+
activemodel:
|
3
|
+
errors:
|
4
|
+
messages:
|
5
|
+
taken: è già utilizzato
|
6
|
+
|
7
|
+
mongoid:
|
8
|
+
errors:
|
9
|
+
messages:
|
10
|
+
document_not_found:
|
11
|
+
Documento non trovato per la classe %{klass} con id(s) %{identifiers}.
|
12
|
+
invalid_database:
|
13
|
+
Il database dovrebbe essere un Mongo::DB, non %{name}.
|
14
|
+
invalid_type:
|
15
|
+
Il campo è stato definito come %{klass} ma ha ricevuto
|
16
|
+
un %{other} con valore %{value}.
|
17
|
+
unsupported_version:
|
18
|
+
MongoDB %{version} not è supportato, aggiorna a %{mongo_version}.
|
19
|
+
validations:
|
20
|
+
Validazione fallita - %{errors}.
|
21
|
+
invalid_collection:
|
22
|
+
Accesso alla collezione per %{klass} non permesso in quanto è
|
23
|
+
un documento embedded, accedi alla collezione dal documento root.
|
24
|
+
invalid_field:
|
25
|
+
Definire un campo con il nome %{name} non è permesso.
|
26
|
+
Non definire campi che vadano in conflitto con nomi di attributi
|
27
|
+
o metodi di Mongoid. Usa Document#instance_methods per consultare
|
28
|
+
la lista dei nomi.
|
29
|
+
too_many_nested_attribute_records:
|
30
|
+
Il numero di attrubuti nested per %{association} è limitato
|
31
|
+
a %{limit} records.
|
32
|
+
embedded_in_must_have_inverse_of:
|
33
|
+
Le opzioni di associazioni embedded_in devono includere inverse_of.
|
34
|
+
dependent_only_references_one_or_many:
|
35
|
+
"L'opzione dependent => destroy|delete è valida solo per
|
36
|
+
associazioni references_one o references_many."
|
37
|
+
association_cant_have_inverse_of:
|
38
|
+
Non è permesso definire un inverse_of in questa associazione.
|
39
|
+
Usa questa opzione solo per embedded_in o references_many as array.
|
@@ -0,0 +1,39 @@
|
|
1
|
+
pl:
|
2
|
+
activemodel:
|
3
|
+
errors:
|
4
|
+
messages:
|
5
|
+
taken: jest już zajęte
|
6
|
+
|
7
|
+
mongoid:
|
8
|
+
errors:
|
9
|
+
messages:
|
10
|
+
document_not_found:
|
11
|
+
Nie znaleziono dokumentu dla klasy %{klass} o id %{identifiers}.
|
12
|
+
invalid_database:
|
13
|
+
Baza danych powinna być typu Mongo::DB, a nie %{name}.
|
14
|
+
invalid_type:
|
15
|
+
Pole zostało zdefiniowane jako %{klass}, ale otrzymano %{other}
|
16
|
+
z wartością %{value}.
|
17
|
+
unsupported_version:
|
18
|
+
MongoDB %{version} nie jest wspierane,
|
19
|
+
zaktualizuj do %{mongo_version}.
|
20
|
+
validations:
|
21
|
+
Weryfikacja nie powiodła się - %{errors}.
|
22
|
+
invalid_collection:
|
23
|
+
Dostęp do kolekcji %{klass} jest niedozwolony ponieważ jest ona
|
24
|
+
dokumentem wbudowanym, użyj kolekcji przez dokument główny.
|
25
|
+
invalid_field:
|
26
|
+
Definiowanie pola o nazwie %{name} jest niedozwolone. Nie definiuj pól
|
27
|
+
konfliktujących z wewnętrznymi atrubutami lub metodami Mongoid.
|
28
|
+
Użyj Document#instance_methods aby zobaczyć te nazwy.
|
29
|
+
too_many_nested_attribute_records:
|
30
|
+
Przyjmowanie zagnieżdżonych atrybutów dla %{association} jest
|
31
|
+
ograniczone do %{limit} rekordów.
|
32
|
+
embedded_in_must_have_inverse_of:
|
33
|
+
Opcje dla asocjacji embedded_in muszą zawierać inverse_of.
|
34
|
+
dependent_only_references_one_or_many:
|
35
|
+
Podana opcja dependent => destroy|delete jest uzasadniona tylko
|
36
|
+
w przypadku asocjacji references_one lub references_many.
|
37
|
+
association_cant_have_inverse_of:
|
38
|
+
Definiowanie inverse_of dla tej asocjacji jest niedozwolone. Używaj
|
39
|
+
tej opcji tylko z embedded_in lub references_many as array.
|
@@ -0,0 +1,40 @@
|
|
1
|
+
pt:
|
2
|
+
activemodel:
|
3
|
+
errors:
|
4
|
+
messages:
|
5
|
+
taken: já está utilizada
|
6
|
+
|
7
|
+
mongoid:
|
8
|
+
errors:
|
9
|
+
messages:
|
10
|
+
document_not_found:
|
11
|
+
Nenhum documento encontrado para a classe %{klass} com os id(s) %{identifiers}.
|
12
|
+
invalid_database:
|
13
|
+
A base de dados deverá ser uma Mongo::DB, em vez de %{name}.
|
14
|
+
invalid_type:
|
15
|
+
O campo foi definido como %{klass}, mas recebeu uma instância de %{other} com
|
16
|
+
o valor %{value}.
|
17
|
+
unsupported_version:
|
18
|
+
MongoDB %{version} não é suportada, por favor actualize para a
|
19
|
+
versão %{mongo_version}.
|
20
|
+
validations:
|
21
|
+
A validação falhou - %{errors}.
|
22
|
+
invalid_collection:
|
23
|
+
O acesso à colecção para %{klass} não é permitido porque
|
24
|
+
é um documento embebido, por favor aceda à colecção através
|
25
|
+
do documento raiz.
|
26
|
+
invalid_field:
|
27
|
+
Não é permitido definir um campo com o nome %{name}. Não defina
|
28
|
+
campos que entrem em conflito com os nomes dos atributos internos e métodos
|
29
|
+
do Mongoid. Use Document#instance_methods para consultar esses nomes.
|
30
|
+
too_many_nested_attribute_records:
|
31
|
+
A aceitação de atributos encadeados para %{association} encontra-se limitada
|
32
|
+
a %{limit} registos.
|
33
|
+
embedded_in_must_have_inverse_of:
|
34
|
+
As opções para uma associação embedded_in devem incluir inverse_of.
|
35
|
+
dependent_only_references_one_or_many:
|
36
|
+
A opção The dependent => destroy|delete que é fornecida
|
37
|
+
é apenas válida para associações references_one ou references_many.
|
38
|
+
association_cant_have_inverse_of:
|
39
|
+
A definição de inverse_of nesta associação não é permitida. Apenas
|
40
|
+
use esta opção em embedded_in ou references_many como lista.
|
@@ -0,0 +1,40 @@
|
|
1
|
+
sv:
|
2
|
+
activemodel:
|
3
|
+
errors:
|
4
|
+
messages:
|
5
|
+
taken: har redan använts
|
6
|
+
|
7
|
+
mongoid:
|
8
|
+
errors:
|
9
|
+
messages:
|
10
|
+
document_not_found:
|
11
|
+
Inget dokument kunde hittas för klass %{klass} med id %{identifiers}.
|
12
|
+
invalid_database:
|
13
|
+
Databasen bör vara Mongo::DB, inte %{name}.
|
14
|
+
invalid_type:
|
15
|
+
Fältet var definerat som %{klass}, men fick %{other} med
|
16
|
+
värdet %{value}.
|
17
|
+
unsupported_version:
|
18
|
+
MongoDB %{version} stöds ej, vänligen upgradera
|
19
|
+
till %{mongo_version}.
|
20
|
+
validations:
|
21
|
+
Validering misslyckades - %{errors}.
|
22
|
+
invalid_collection:
|
23
|
+
Tillgång till kollektionen för %{klass} är inte tillåten eftersom den
|
24
|
+
är ett inbäddat dokument, vänligen accessa kollektionen från
|
25
|
+
rotdokumentet.
|
26
|
+
invalid_field:
|
27
|
+
Att definera ett fält med namnet %{name} är inte tillåtet. Definera inte
|
28
|
+
fält som är i konflikt med Mongoids interna attribut eller metod
|
29
|
+
namn. Använd Document#instance_methods för att se vilka namn detta innefattar.
|
30
|
+
too_many_nested_attribute_records:
|
31
|
+
Acceptans av nästlade attribut för %{association} är begränsat
|
32
|
+
till %{limit} register.
|
33
|
+
embedded_in_must_have_inverse_of:
|
34
|
+
Alternativ för en embedded_in association måste innehålla inverse_of.
|
35
|
+
dependent_only_references_one_or_many:
|
36
|
+
Alternativet dependent => destroy|delete som angavs
|
37
|
+
är endast giltigt för references_one eller references_many associationer.
|
38
|
+
association_cant_have_inverse_of:
|
39
|
+
Att definera inverse_of på denna association är inte tillåtet. Använd
|
40
|
+
endast detta alternativ på embedded_in eller references_many as array.
|
data/lib/mongoid.rb
CHANGED
@@ -41,7 +41,9 @@ require "active_model/validator"
|
|
41
41
|
require "active_model/validations"
|
42
42
|
require "will_paginate/collection"
|
43
43
|
require "mongo"
|
44
|
+
require "mongoid/errors"
|
44
45
|
require "mongoid/extensions"
|
46
|
+
require "mongoid/safe"
|
45
47
|
require "mongoid/associations"
|
46
48
|
require "mongoid/atomicity"
|
47
49
|
require "mongoid/attributes"
|
@@ -55,7 +57,6 @@ require "mongoid/cursor"
|
|
55
57
|
require "mongoid/deprecation"
|
56
58
|
require "mongoid/dirty"
|
57
59
|
require "mongoid/extras"
|
58
|
-
require "mongoid/errors"
|
59
60
|
require "mongoid/factory"
|
60
61
|
require "mongoid/field"
|
61
62
|
require "mongoid/fields"
|
@@ -69,6 +70,7 @@ require "mongoid/keys"
|
|
69
70
|
require "mongoid/logger"
|
70
71
|
require "mongoid/matchers"
|
71
72
|
require "mongoid/memoization"
|
73
|
+
require "mongoid/modifiers"
|
72
74
|
require "mongoid/named_scope"
|
73
75
|
require "mongoid/paths"
|
74
76
|
require "mongoid/persistence"
|
@@ -87,9 +89,12 @@ if defined?(Rails)
|
|
87
89
|
require "mongoid/railtie"
|
88
90
|
end
|
89
91
|
|
92
|
+
# add english load path by default
|
93
|
+
I18n.load_path << File.join(File.dirname(__FILE__), "config", "locales", "en.yml")
|
94
|
+
|
90
95
|
module Mongoid #:nodoc
|
91
96
|
|
92
|
-
MONGODB_VERSION = "1.
|
97
|
+
MONGODB_VERSION = "1.6.0"
|
93
98
|
|
94
99
|
class << self
|
95
100
|
|
data/lib/mongoid/associations.rb
CHANGED
@@ -99,13 +99,10 @@ module Mongoid # :nodoc:
|
|
99
99
|
# embedded_in :person, :inverse_of => :addresses
|
100
100
|
# end
|
101
101
|
def embedded_in(name, options = {}, &block)
|
102
|
-
|
103
|
-
|
104
|
-
"Options for embedded_in association must include :inverse_of"
|
105
|
-
)
|
106
|
-
end
|
102
|
+
opts = optionize(name, options, nil, &block)
|
103
|
+
Associations::EmbeddedIn.validate_options(opts)
|
107
104
|
self.embedded = true
|
108
|
-
associate(Associations::EmbeddedIn,
|
105
|
+
associate(Associations::EmbeddedIn, opts)
|
109
106
|
end
|
110
107
|
|
111
108
|
# Adds the association from a parent document to its children. The name
|
@@ -128,7 +125,9 @@ module Mongoid # :nodoc:
|
|
128
125
|
# embedded_in :person, :inverse_of => :addresses
|
129
126
|
# end
|
130
127
|
def embeds_many(name, options = {}, &block)
|
131
|
-
|
128
|
+
opts = optionize(name, options, nil, &block)
|
129
|
+
Associations::EmbedsMany.validate_options(opts)
|
130
|
+
associate(Associations::EmbedsMany, opts)
|
132
131
|
end
|
133
132
|
|
134
133
|
alias :embed_many :embeds_many
|
@@ -155,6 +154,7 @@ module Mongoid # :nodoc:
|
|
155
154
|
def embeds_one(name, options = {}, &block)
|
156
155
|
opts = optionize(name, options, nil, &block)
|
157
156
|
type = Associations::EmbedsOne
|
157
|
+
type.validate_options(opts)
|
158
158
|
associate(type, opts)
|
159
159
|
add_builder(type, opts)
|
160
160
|
add_creator(type, opts)
|
@@ -178,8 +178,9 @@ module Mongoid # :nodoc:
|
|
178
178
|
#
|
179
179
|
def referenced_in(name, options = {}, &block)
|
180
180
|
opts = optionize(name, options, constraint(name, options, :in), &block)
|
181
|
+
Associations::ReferencedIn.validate_options(opts)
|
181
182
|
associate(Associations::ReferencedIn, opts)
|
182
|
-
field(opts.foreign_key, :
|
183
|
+
field(opts.foreign_key, :inverse_class_name => opts.class_name, :identity => true)
|
183
184
|
index(opts.foreign_key, :background => true) if !embedded? && opts.index
|
184
185
|
set_callback(:save, :before) { |document| document.update_foreign_keys }
|
185
186
|
end
|
@@ -340,7 +341,13 @@ module Mongoid # :nodoc:
|
|
340
341
|
if (options[:stored_as] == :array)
|
341
342
|
foreign_key = "#{name.to_s.singularize}_ids"
|
342
343
|
opts = optionize(name, options, constraint(name, options, :many_as_array), &block)
|
343
|
-
field(
|
344
|
+
field(
|
345
|
+
foreign_key,
|
346
|
+
:type => Array,
|
347
|
+
:default => [],
|
348
|
+
:identity => true,
|
349
|
+
:inverse_class_name => opts.class_name
|
350
|
+
)
|
344
351
|
index(foreign_key, :background => true) if opts.index
|
345
352
|
associate(Associations::ReferencesManyAsArray, opts)
|
346
353
|
else
|
@@ -57,6 +57,17 @@ module Mongoid #:nodoc:
|
|
57
57
|
def update(target, child, options)
|
58
58
|
new(child, options, target)
|
59
59
|
end
|
60
|
+
|
61
|
+
# Validate the options passed to the embedded in macro, to encapsulate
|
62
|
+
# the behavior in this class instead of the associations module.
|
63
|
+
#
|
64
|
+
# Options:
|
65
|
+
#
|
66
|
+
# options: Thank you captain obvious.
|
67
|
+
def validate_options(options = {})
|
68
|
+
check_dependent_not_allowed!(options)
|
69
|
+
check_inverse_must_be_defined!(options)
|
70
|
+
end
|
60
71
|
end
|
61
72
|
end
|
62
73
|
end
|
@@ -175,8 +175,16 @@ module Mongoid #:nodoc:
|
|
175
175
|
# The newly build target Document.
|
176
176
|
def nested_build(attributes, options = {})
|
177
177
|
@parent.instance_variable_set(:@building_nested, true)
|
178
|
+
id_index, reordering = {}, false
|
178
179
|
attributes.each do |index, attrs|
|
179
|
-
|
180
|
+
document = if attrs["id"].present?
|
181
|
+
reordering = true
|
182
|
+
id_index[attrs["id"]] = index.to_i
|
183
|
+
detect { |document| document.id.to_s == attrs["id"].to_s }
|
184
|
+
else
|
185
|
+
detect { |document| document._index == index.to_i }
|
186
|
+
end
|
187
|
+
if document
|
180
188
|
if options && options[:allow_destroy] && Boolean.set(attrs['_destroy'])
|
181
189
|
@target.delete(document)
|
182
190
|
document.destroy
|
@@ -184,7 +192,14 @@ module Mongoid #:nodoc:
|
|
184
192
|
document.write_attributes(attrs)
|
185
193
|
end
|
186
194
|
else
|
187
|
-
build(attrs)
|
195
|
+
document = build(attrs)
|
196
|
+
id_index[document.id.to_s] = index.to_i
|
197
|
+
end
|
198
|
+
end
|
199
|
+
if reordering
|
200
|
+
@target.sort! do |a, b|
|
201
|
+
ai, bi = id_index[a.id.to_s], id_index[b.id.to_s]
|
202
|
+
ai.nil? ? (bi.nil? ? 0 : 1) : (bi.nil? ? -1 : ai <=> bi)
|
188
203
|
end
|
189
204
|
end
|
190
205
|
@target.each_with_index { |document, index| document._index = index }
|
@@ -267,6 +282,17 @@ module Mongoid #:nodoc:
|
|
267
282
|
new(parent, options)
|
268
283
|
end
|
269
284
|
end
|
285
|
+
|
286
|
+
# Validate the options passed to the embeds many macro, to encapsulate
|
287
|
+
# the behavior in this class instead of the associations module.
|
288
|
+
#
|
289
|
+
# Options:
|
290
|
+
#
|
291
|
+
# options: Thank you captain obvious.
|
292
|
+
def validate_options(options = {})
|
293
|
+
check_dependent_not_allowed!(options)
|
294
|
+
check_inverse_not_allowed!(options)
|
295
|
+
end
|
270
296
|
end
|
271
297
|
end
|
272
298
|
end
|