stonegao-mongoid 2.0.0.rc.6
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/LICENSE +20 -0
- data/README.rdoc +50 -0
- data/Rakefile +51 -0
- data/lib/config/locales/bg.yml +44 -0
- data/lib/config/locales/de.yml +44 -0
- data/lib/config/locales/en.yml +45 -0
- data/lib/config/locales/es.yml +44 -0
- data/lib/config/locales/fr.yml +45 -0
- data/lib/config/locales/hu.yml +47 -0
- data/lib/config/locales/it.yml +42 -0
- data/lib/config/locales/kr.yml +68 -0
- data/lib/config/locales/nl.yml +42 -0
- data/lib/config/locales/pl.yml +42 -0
- data/lib/config/locales/pt-br.yml +43 -0
- data/lib/config/locales/pt.yml +43 -0
- data/lib/config/locales/ro.yml +49 -0
- data/lib/config/locales/sv.yml +43 -0
- data/lib/config/locales/zh-CN.yml +34 -0
- data/lib/mongoid/atomicity.rb +111 -0
- data/lib/mongoid/attributes.rb +251 -0
- data/lib/mongoid/callbacks.rb +13 -0
- data/lib/mongoid/collection.rb +137 -0
- data/lib/mongoid/collections/cyclic_iterator.rb +34 -0
- data/lib/mongoid/collections/master.rb +29 -0
- data/lib/mongoid/collections/operations.rb +42 -0
- data/lib/mongoid/collections/slaves.rb +45 -0
- data/lib/mongoid/collections.rb +70 -0
- data/lib/mongoid/components.rb +45 -0
- data/lib/mongoid/config/database.rb +167 -0
- data/lib/mongoid/config/replset_database.rb +48 -0
- data/lib/mongoid/config.rb +343 -0
- data/lib/mongoid/contexts/enumerable/sort.rb +43 -0
- data/lib/mongoid/contexts/enumerable.rb +226 -0
- data/lib/mongoid/contexts/ids.rb +25 -0
- data/lib/mongoid/contexts/mongo.rb +345 -0
- data/lib/mongoid/contexts/paging.rb +50 -0
- data/lib/mongoid/contexts.rb +21 -0
- data/lib/mongoid/copyable.rb +44 -0
- data/lib/mongoid/criteria.rb +325 -0
- data/lib/mongoid/criterion/complex.rb +34 -0
- data/lib/mongoid/criterion/creational.rb +34 -0
- data/lib/mongoid/criterion/exclusion.rb +67 -0
- data/lib/mongoid/criterion/inclusion.rb +134 -0
- data/lib/mongoid/criterion/inspection.rb +20 -0
- data/lib/mongoid/criterion/optional.rb +213 -0
- data/lib/mongoid/criterion/selector.rb +74 -0
- data/lib/mongoid/cursor.rb +81 -0
- data/lib/mongoid/default_scope.rb +28 -0
- data/lib/mongoid/dirty.rb +251 -0
- data/lib/mongoid/document.rb +256 -0
- 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/unsaved_document.rb +23 -0
- data/lib/mongoid/errors/unsupported_version.rb +21 -0
- data/lib/mongoid/errors/validations.rb +24 -0
- data/lib/mongoid/errors.rb +12 -0
- data/lib/mongoid/extensions/array/conversions.rb +23 -0
- data/lib/mongoid/extensions/array/parentization.rb +13 -0
- data/lib/mongoid/extensions/big_decimal/conversions.rb +19 -0
- data/lib/mongoid/extensions/binary/conversions.rb +17 -0
- data/lib/mongoid/extensions/boolean/conversions.rb +27 -0
- data/lib/mongoid/extensions/date/conversions.rb +25 -0
- data/lib/mongoid/extensions/datetime/conversions.rb +12 -0
- data/lib/mongoid/extensions/false_class/equality.rb +13 -0
- data/lib/mongoid/extensions/float/conversions.rb +20 -0
- data/lib/mongoid/extensions/hash/conversions.rb +19 -0
- data/lib/mongoid/extensions/hash/criteria_helpers.rb +22 -0
- data/lib/mongoid/extensions/hash/scoping.rb +12 -0
- data/lib/mongoid/extensions/integer/conversions.rb +20 -0
- data/lib/mongoid/extensions/nil/collectionization.rb +12 -0
- data/lib/mongoid/extensions/object/conversions.rb +25 -0
- data/lib/mongoid/extensions/object/reflections.rb +17 -0
- data/lib/mongoid/extensions/object/yoda.rb +27 -0
- data/lib/mongoid/extensions/object_id/conversions.rb +57 -0
- data/lib/mongoid/extensions/proc/scoping.rb +12 -0
- data/lib/mongoid/extensions/set/conversions.rb +20 -0
- data/lib/mongoid/extensions/string/conversions.rb +34 -0
- data/lib/mongoid/extensions/string/inflections.rb +97 -0
- data/lib/mongoid/extensions/symbol/conversions.rb +21 -0
- data/lib/mongoid/extensions/symbol/inflections.rb +40 -0
- data/lib/mongoid/extensions/time_conversions.rb +38 -0
- data/lib/mongoid/extensions/true_class/equality.rb +13 -0
- data/lib/mongoid/extensions.rb +116 -0
- data/lib/mongoid/extras.rb +61 -0
- data/lib/mongoid/factory.rb +20 -0
- data/lib/mongoid/field.rb +95 -0
- data/lib/mongoid/fields.rb +138 -0
- data/lib/mongoid/finders.rb +173 -0
- data/lib/mongoid/hierarchy.rb +85 -0
- data/lib/mongoid/identity.rb +89 -0
- data/lib/mongoid/indexes.rb +38 -0
- data/lib/mongoid/inspection.rb +58 -0
- data/lib/mongoid/javascript/functions.yml +37 -0
- data/lib/mongoid/javascript.rb +21 -0
- data/lib/mongoid/json.rb +16 -0
- data/lib/mongoid/keys.rb +77 -0
- data/lib/mongoid/logger.rb +18 -0
- data/lib/mongoid/matchers/all.rb +11 -0
- data/lib/mongoid/matchers/default.rb +27 -0
- data/lib/mongoid/matchers/exists.rb +13 -0
- data/lib/mongoid/matchers/gt.rb +11 -0
- data/lib/mongoid/matchers/gte.rb +11 -0
- data/lib/mongoid/matchers/in.rb +11 -0
- data/lib/mongoid/matchers/lt.rb +11 -0
- data/lib/mongoid/matchers/lte.rb +11 -0
- data/lib/mongoid/matchers/ne.rb +11 -0
- data/lib/mongoid/matchers/nin.rb +11 -0
- data/lib/mongoid/matchers/size.rb +11 -0
- data/lib/mongoid/matchers.rb +55 -0
- data/lib/mongoid/modifiers/command.rb +18 -0
- data/lib/mongoid/modifiers/inc.rb +24 -0
- data/lib/mongoid/modifiers.rb +24 -0
- data/lib/mongoid/multi_database.rb +11 -0
- data/lib/mongoid/multi_parameter_attributes.rb +80 -0
- data/lib/mongoid/named_scope.rb +36 -0
- data/lib/mongoid/nested_attributes.rb +43 -0
- data/lib/mongoid/paranoia.rb +103 -0
- data/lib/mongoid/paths.rb +61 -0
- data/lib/mongoid/persistence/command.rb +59 -0
- data/lib/mongoid/persistence/insert.rb +53 -0
- data/lib/mongoid/persistence/insert_embedded.rb +42 -0
- data/lib/mongoid/persistence/remove.rb +44 -0
- data/lib/mongoid/persistence/remove_all.rb +40 -0
- data/lib/mongoid/persistence/remove_embedded.rb +48 -0
- data/lib/mongoid/persistence/update.rb +76 -0
- data/lib/mongoid/persistence.rb +237 -0
- data/lib/mongoid/railtie.rb +129 -0
- data/lib/mongoid/railties/database.rake +171 -0
- data/lib/mongoid/railties/document.rb +12 -0
- data/lib/mongoid/relations/accessors.rb +157 -0
- data/lib/mongoid/relations/auto_save.rb +34 -0
- data/lib/mongoid/relations/binding.rb +26 -0
- data/lib/mongoid/relations/bindings/embedded/in.rb +82 -0
- data/lib/mongoid/relations/bindings/embedded/many.rb +98 -0
- data/lib/mongoid/relations/bindings/embedded/one.rb +66 -0
- data/lib/mongoid/relations/bindings/referenced/in.rb +74 -0
- data/lib/mongoid/relations/bindings/referenced/many.rb +96 -0
- data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +99 -0
- data/lib/mongoid/relations/bindings/referenced/one.rb +66 -0
- data/lib/mongoid/relations/bindings.rb +9 -0
- data/lib/mongoid/relations/builder.rb +42 -0
- data/lib/mongoid/relations/builders/embedded/in.rb +25 -0
- data/lib/mongoid/relations/builders/embedded/many.rb +32 -0
- data/lib/mongoid/relations/builders/embedded/one.rb +26 -0
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +116 -0
- data/lib/mongoid/relations/builders/nested_attributes/one.rb +135 -0
- data/lib/mongoid/relations/builders/referenced/in.rb +32 -0
- data/lib/mongoid/relations/builders/referenced/many.rb +26 -0
- data/lib/mongoid/relations/builders/referenced/many_to_many.rb +29 -0
- data/lib/mongoid/relations/builders/referenced/one.rb +30 -0
- data/lib/mongoid/relations/builders.rb +79 -0
- data/lib/mongoid/relations/cascading/delete.rb +19 -0
- data/lib/mongoid/relations/cascading/destroy.rb +19 -0
- data/lib/mongoid/relations/cascading/nullify.rb +18 -0
- data/lib/mongoid/relations/cascading/strategy.rb +26 -0
- data/lib/mongoid/relations/cascading.rb +55 -0
- data/lib/mongoid/relations/constraint.rb +45 -0
- data/lib/mongoid/relations/cyclic.rb +97 -0
- data/lib/mongoid/relations/embedded/in.rb +173 -0
- data/lib/mongoid/relations/embedded/many.rb +483 -0
- data/lib/mongoid/relations/embedded/one.rb +170 -0
- data/lib/mongoid/relations/macros.rb +306 -0
- data/lib/mongoid/relations/many.rb +171 -0
- data/lib/mongoid/relations/metadata.rb +533 -0
- data/lib/mongoid/relations/nested_builder.rb +68 -0
- data/lib/mongoid/relations/one.rb +47 -0
- data/lib/mongoid/relations/polymorphic.rb +54 -0
- data/lib/mongoid/relations/proxy.rb +128 -0
- data/lib/mongoid/relations/referenced/in.rb +216 -0
- data/lib/mongoid/relations/referenced/many.rb +443 -0
- data/lib/mongoid/relations/referenced/many_to_many.rb +344 -0
- data/lib/mongoid/relations/referenced/one.rb +206 -0
- data/lib/mongoid/relations/reflections.rb +45 -0
- data/lib/mongoid/relations.rb +105 -0
- data/lib/mongoid/safe.rb +23 -0
- data/lib/mongoid/safety.rb +207 -0
- data/lib/mongoid/scope.rb +31 -0
- data/lib/mongoid/serialization.rb +99 -0
- data/lib/mongoid/state.rb +66 -0
- data/lib/mongoid/timestamps.rb +38 -0
- data/lib/mongoid/validations/associated.rb +42 -0
- data/lib/mongoid/validations/uniqueness.rb +85 -0
- data/lib/mongoid/validations.rb +117 -0
- data/lib/mongoid/version.rb +4 -0
- data/lib/mongoid/versioning.rb +51 -0
- data/lib/mongoid.rb +139 -0
- data/lib/rails/generators/mongoid/config/config_generator.rb +25 -0
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +23 -0
- data/lib/rails/generators/mongoid/model/model_generator.rb +24 -0
- data/lib/rails/generators/mongoid/model/templates/model.rb +17 -0
- data/lib/rails/generators/mongoid_generator.rb +61 -0
- data/lib/rails/mongoid.rb +57 -0
- metadata +380 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
module Mongoid # :nodoc:
|
|
3
|
+
module Relations #:nodoc:
|
|
4
|
+
|
|
5
|
+
# This class is the superclass for all relation proxy objects, and contains
|
|
6
|
+
# common behaviour for all of them.
|
|
7
|
+
class Proxy
|
|
8
|
+
|
|
9
|
+
# We undefine most methods to get them sent through to the target.
|
|
10
|
+
instance_methods.each do |method|
|
|
11
|
+
undef_method(method) unless
|
|
12
|
+
method =~ /(^__|^send$|^object_id$|^extend$|^tap$)/
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
attr_accessor :base, :loaded, :metadata, :target
|
|
16
|
+
|
|
17
|
+
# Backwards compatibiloty with Mongoid beta releases.
|
|
18
|
+
delegate :klass, :to => :metadata
|
|
19
|
+
|
|
20
|
+
# Convenience for setting the target and the metadata properties since
|
|
21
|
+
# all proxies will need to do this.
|
|
22
|
+
#
|
|
23
|
+
# @example Initialize the proxy.
|
|
24
|
+
# proxy.init(person, name, metadata)
|
|
25
|
+
#
|
|
26
|
+
# @param [ Document ] base The base document on the proxy.
|
|
27
|
+
# @param [ Document, Array<Document> ] target The target of the proxy.
|
|
28
|
+
# @param [ Metadata ] metadata The relation's metadata.
|
|
29
|
+
#
|
|
30
|
+
# @since 2.0.0.rc.1
|
|
31
|
+
def init(base, target, metadata, &block)
|
|
32
|
+
@base, @building, @target, @metadata = base, false, target, metadata
|
|
33
|
+
yield block if block_given?
|
|
34
|
+
extend Module.new(&metadata.extension) if metadata.extension?
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
protected
|
|
38
|
+
|
|
39
|
+
# Yields to the block to allow the building flag to get set and unset for
|
|
40
|
+
# the supplied code.
|
|
41
|
+
#
|
|
42
|
+
# @example Set the building status.
|
|
43
|
+
# person.building { @target << Post.new }
|
|
44
|
+
#
|
|
45
|
+
# @since 2.0.0.rc.1
|
|
46
|
+
def building(&block)
|
|
47
|
+
@building = true
|
|
48
|
+
yield block if block_given?
|
|
49
|
+
@building = false
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Convenience method for determining if we are building an association.
|
|
53
|
+
# We never want to save in this case.
|
|
54
|
+
#
|
|
55
|
+
# @example Are we currently building?
|
|
56
|
+
# person.posts.building?
|
|
57
|
+
#
|
|
58
|
+
# @return [ true, false ] True if currently building, false if not.
|
|
59
|
+
#
|
|
60
|
+
# @since 2.0.0.rc.1
|
|
61
|
+
def building?
|
|
62
|
+
!!@building
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Return a new document for the type of class we want to instantiate.
|
|
66
|
+
# If the type is provided use that, otherwise the klass from the
|
|
67
|
+
# metadata.
|
|
68
|
+
#
|
|
69
|
+
# @example Get an instantiated document.
|
|
70
|
+
# proxy.instantiated(Person)
|
|
71
|
+
#
|
|
72
|
+
# @param [ Class ] type The type of class to instantiate.
|
|
73
|
+
#
|
|
74
|
+
# @return [ Document ] The freshly created document.
|
|
75
|
+
#
|
|
76
|
+
# @since 2.0.0.rc.1
|
|
77
|
+
def instantiated(type = nil)
|
|
78
|
+
type ? type.instantiate : metadata.klass.instantiate
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Determines if the target been loaded into memory or not.
|
|
82
|
+
#
|
|
83
|
+
# @example Is the proxy loaded?
|
|
84
|
+
# proxy.loaded?
|
|
85
|
+
#
|
|
86
|
+
# @return [ true, false ] True if loaded, false if not.
|
|
87
|
+
#
|
|
88
|
+
# @since 2.0.0.rc.1
|
|
89
|
+
def loaded?
|
|
90
|
+
!!@loaded
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Takes the supplied documents and sets the metadata on them. Used when
|
|
94
|
+
# creating new documents and adding them to the relation.
|
|
95
|
+
#
|
|
96
|
+
# @example Set the metadata.
|
|
97
|
+
# proxy.characterize(addresses)
|
|
98
|
+
#
|
|
99
|
+
# @param [ Array<Document> ] documents The documents to set metadata on.
|
|
100
|
+
#
|
|
101
|
+
# @since 2.0.0.rc.4
|
|
102
|
+
def characterize(documents)
|
|
103
|
+
documents.each { |doc| characterize_one(doc) }
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Takes the supplied document and sets the metadata on it.
|
|
107
|
+
#
|
|
108
|
+
# @example Set the metadata.
|
|
109
|
+
# proxt.characterize_one(name)
|
|
110
|
+
#
|
|
111
|
+
# @param [ Document ] document The document to set on.
|
|
112
|
+
#
|
|
113
|
+
# @since 2.0.0.rc.4
|
|
114
|
+
def characterize_one(document)
|
|
115
|
+
document.metadata = metadata unless document.metadata
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Default behavior of method missing should be to delegate all calls
|
|
119
|
+
# to the target of the proxy. This can be overridden in special cases.
|
|
120
|
+
#
|
|
121
|
+
# @param [ String, Symbol ] name The name of the method.
|
|
122
|
+
# @param [ Array ] *args The arguments passed to the method.
|
|
123
|
+
def method_missing(name, *args, &block)
|
|
124
|
+
target.send(name, *args, &block)
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
module Mongoid # :nodoc:
|
|
3
|
+
module Relations #:nodoc:
|
|
4
|
+
module Referenced #:nodoc:
|
|
5
|
+
|
|
6
|
+
# This class handles all behaviour for relations that are either
|
|
7
|
+
# one-to-many or one-to-one, where the foreign key is store on this side
|
|
8
|
+
# of the relation and the reference is to document(s) in another
|
|
9
|
+
# collection.
|
|
10
|
+
class In < Relations::One
|
|
11
|
+
|
|
12
|
+
# Binds the base object to the inverse of the relation. This is so we
|
|
13
|
+
# are referenced to the actual objects themselves and dont hit the
|
|
14
|
+
# database twice when setting the relations up.
|
|
15
|
+
#
|
|
16
|
+
# This is called after first creating the relation, or if a new object
|
|
17
|
+
# is set on the relation.
|
|
18
|
+
#
|
|
19
|
+
# @example Bind the relation.
|
|
20
|
+
# game.person.bind
|
|
21
|
+
#
|
|
22
|
+
# @param [ Hash ] options The options to bind with.
|
|
23
|
+
#
|
|
24
|
+
# @option options [ true, false ] :binding Are we in build mode?
|
|
25
|
+
# @option options [ true, false ] :continue Continue binding the
|
|
26
|
+
# inverse?
|
|
27
|
+
#
|
|
28
|
+
# @since 2.0.0.rc.1
|
|
29
|
+
def bind(options = {})
|
|
30
|
+
binding.bind(options)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Instantiate a new referenced_in relation.
|
|
34
|
+
#
|
|
35
|
+
# @example Create the new relation.
|
|
36
|
+
# Referenced::In.new(game, person, metadata)
|
|
37
|
+
#
|
|
38
|
+
# @param [ Document ] base The document this relation hangs off of.
|
|
39
|
+
# @param [ Document, Array<Document> ] target The target (parent) of the
|
|
40
|
+
# relation.
|
|
41
|
+
# @param [ Metadata ] metadata The relation's metadata.
|
|
42
|
+
def initialize(base, target, metadata)
|
|
43
|
+
init(base, target, metadata) do
|
|
44
|
+
characterize_one(target)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Substitutes the supplied target documents for the existing document
|
|
49
|
+
# in the relation.
|
|
50
|
+
#
|
|
51
|
+
# @example Substitute the relation.
|
|
52
|
+
# name.substitute(new_name)
|
|
53
|
+
#
|
|
54
|
+
# @param [ Document, Array<Document> ] new_target The replacement.
|
|
55
|
+
# @param [ true, false ] building Are we in build mode?
|
|
56
|
+
#
|
|
57
|
+
# @return [ In, nil ] The relation or nil.
|
|
58
|
+
#
|
|
59
|
+
# @since 2.0.0.rc.1
|
|
60
|
+
def substitute(new_target, options = {})
|
|
61
|
+
old_target = target
|
|
62
|
+
tap do |relation|
|
|
63
|
+
relation.target = new_target
|
|
64
|
+
if new_target
|
|
65
|
+
bind(options)
|
|
66
|
+
else
|
|
67
|
+
unbind(old_target, options)
|
|
68
|
+
nil
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Unbinds the base object to the inverse of the relation. This occurs
|
|
74
|
+
# when setting a side of the relation to nil.
|
|
75
|
+
#
|
|
76
|
+
# @example Unbind the relation.
|
|
77
|
+
# game.person.unbind
|
|
78
|
+
#
|
|
79
|
+
# @param [ Document, Array<Document> ] old_target The previous target.
|
|
80
|
+
# @param [ Hash ] options The options to bind with.
|
|
81
|
+
#
|
|
82
|
+
# @option options [ true, false ] :binding Are we in build mode?
|
|
83
|
+
# @option options [ true, false ] :continue Continue binding the
|
|
84
|
+
# inverse?
|
|
85
|
+
#
|
|
86
|
+
# @since 2.0.0.rc.1
|
|
87
|
+
def unbind(old_target, options = {})
|
|
88
|
+
binding(old_target).unbind(options)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
private
|
|
92
|
+
|
|
93
|
+
# Instantiate the binding associated with this relation.
|
|
94
|
+
#
|
|
95
|
+
# @example Get the binding object.
|
|
96
|
+
# binding([ address ])
|
|
97
|
+
#
|
|
98
|
+
# @param [ Document, Array<Document> ] new_target The replacement.
|
|
99
|
+
#
|
|
100
|
+
# @return [ Binding ] The binding object.
|
|
101
|
+
#
|
|
102
|
+
# @since 2.0.0.rc.1
|
|
103
|
+
def binding(new_target = nil)
|
|
104
|
+
Bindings::Referenced::In.new(base, new_target || target, metadata)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
class << self
|
|
108
|
+
|
|
109
|
+
# Return the builder that is responsible for generating the documents
|
|
110
|
+
# that will be used by this relation.
|
|
111
|
+
#
|
|
112
|
+
# @example Get the builder.
|
|
113
|
+
# Referenced::In.builder(meta, object)
|
|
114
|
+
#
|
|
115
|
+
# @param [ Metadata ] meta The metadata of the relation.
|
|
116
|
+
# @param [ Document, Hash ] object A document or attributes to build
|
|
117
|
+
# with.
|
|
118
|
+
#
|
|
119
|
+
# @return [ Builder ] A new builder object.
|
|
120
|
+
#
|
|
121
|
+
# @since 2.0.0.rc.1
|
|
122
|
+
def builder(meta, object)
|
|
123
|
+
Builders::Referenced::In.new(meta, object)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Returns true if the relation is an embedded one. In this case
|
|
127
|
+
# always false.
|
|
128
|
+
#
|
|
129
|
+
# @example Is this relation embedded?
|
|
130
|
+
# Referenced::In.embedded?
|
|
131
|
+
#
|
|
132
|
+
# @return [ false ] Always false.
|
|
133
|
+
#
|
|
134
|
+
# @since 2.0.0.rc.1
|
|
135
|
+
def embedded?
|
|
136
|
+
false
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# Get the default value for the foreign key.
|
|
140
|
+
#
|
|
141
|
+
# @example Get the default.
|
|
142
|
+
# Referenced::In.foreign_key_default
|
|
143
|
+
#
|
|
144
|
+
# @return [ nil ] Always nil.
|
|
145
|
+
#
|
|
146
|
+
# @since 2.0.0.rc.1
|
|
147
|
+
def foreign_key_default
|
|
148
|
+
nil
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# Returns the suffix of the foreign key field, either "_id" or "_ids".
|
|
152
|
+
#
|
|
153
|
+
# @example Get the suffix for the foreign key.
|
|
154
|
+
# Referenced::In.foreign_key_suffix
|
|
155
|
+
#
|
|
156
|
+
# @return [ String ] "_id"
|
|
157
|
+
#
|
|
158
|
+
# @since 2.0.0.rc.1
|
|
159
|
+
def foreign_key_suffix
|
|
160
|
+
"_id"
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# Returns the macro for this relation. Used mostly as a helper in
|
|
164
|
+
# reflection.
|
|
165
|
+
#
|
|
166
|
+
# @example Get the macro.
|
|
167
|
+
# Referenced::In.macro
|
|
168
|
+
#
|
|
169
|
+
# @return [ Symbol ] :referenced_in
|
|
170
|
+
def macro
|
|
171
|
+
:referenced_in
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
# Return the nested builder that is responsible for generating the documents
|
|
175
|
+
# that will be used by this relation.
|
|
176
|
+
#
|
|
177
|
+
# @example Get the nested builder.
|
|
178
|
+
# Referenced::In.builder(attributes, options)
|
|
179
|
+
#
|
|
180
|
+
# @param [ Metadata ] metadata The relation metadata.
|
|
181
|
+
# @param [ Hash ] attributes The attributes to build with.
|
|
182
|
+
# @param [ Hash ] options The options for the builder.
|
|
183
|
+
#
|
|
184
|
+
# @option options [ true, false ] :allow_destroy Can documents be
|
|
185
|
+
# deleted?
|
|
186
|
+
# @option options [ Integer ] :limit Max number of documents to
|
|
187
|
+
# create at once.
|
|
188
|
+
# @option options [ Proc, Symbol ] :reject_if If documents match this
|
|
189
|
+
# option then they are ignored.
|
|
190
|
+
# @option options [ true, false ] :update_only Only existing documents
|
|
191
|
+
# can be modified.
|
|
192
|
+
#
|
|
193
|
+
# @return [ NestedBuilder ] A newly instantiated nested builder object.
|
|
194
|
+
#
|
|
195
|
+
# @since 2.0.0.rc.1
|
|
196
|
+
def nested_builder(metadata, attributes, options)
|
|
197
|
+
Builders::NestedAttributes::One.new(metadata, attributes, options)
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# Tells the caller if this relation is one that stores the foreign
|
|
201
|
+
# key on its own objects.
|
|
202
|
+
#
|
|
203
|
+
# @example Does this relation store a foreign key?
|
|
204
|
+
# Referenced::In.stores_foreign_key?
|
|
205
|
+
#
|
|
206
|
+
# @return [ true ] Always true.
|
|
207
|
+
#
|
|
208
|
+
# @since 2.0.0.rc.1
|
|
209
|
+
def stores_foreign_key?
|
|
210
|
+
true
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
end
|