Module: ActiveGraph::Node::HasN
- Extended by:
- ActiveSupport::Concern
- Included in:
- ActiveGraph::Node
- Defined in:
- lib/active_graph/node/has_n.rb,
lib/active_graph/node/has_n/association.rb,
lib/active_graph/node/has_n/association/rel_factory.rb,
lib/active_graph/node/has_n/association_cypher_methods.rb
Defined Under Namespace
Modules: AssociationCypherMethods, ClassMethods
Classes: Association, AssociationProxy, HasOneConstraintError, NonPersistedNodeError
Instance Method Summary
collapse
Instance Method Details
#association_proxy(name, options = {}) ⇒ Object
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
# File 'lib/active_graph/node/has_n.rb', line 212
def association_proxy(name, options = {})
name = name.to_sym
hash = association_proxy_hash(name, options)
association_proxy_cache_fetch(hash) do
if result_cache = self.instance_variable_get('@source_proxy_result_cache')
cache = nil
result_cache.inject(nil) do |proxy_to_return, object|
proxy = fresh_association_proxy(name, options.merge(start_object: object),
proc { (cache ||= previous_proxy_results_by_previous_id(result_cache, name))[object.neo_id] })
object.association_proxy_cache[hash] = proxy
(self == object ? proxy : proxy_to_return)
end
else
fresh_association_proxy(name, options)
end
end
end
|
#association_proxy_cache ⇒ Object
Returns the current AssociationProxy cache for the association cache. It is in the format { :association_name => AssociationProxy} This is so that we
-
don't need to re-build the QueryProxy objects
-
also because the QueryProxy object caches it's results
-
so we don't need to query again
-
so that we can cache results from association calls or eager loading
193
194
195
|
# File 'lib/active_graph/node/has_n.rb', line 193
def association_proxy_cache
@association_proxy_cache ||= {}
end
|
#association_proxy_cache_fetch(key) ⇒ Object
197
198
199
200
201
202
|
# File 'lib/active_graph/node/has_n.rb', line 197
def association_proxy_cache_fetch(key)
association_proxy_cache.fetch(key) do
value = yield
association_proxy_cache[key] = value
end
end
|
#association_proxy_hash(name, options = {}) ⇒ Object
208
209
210
|
# File 'lib/active_graph/node/has_n.rb', line 208
def association_proxy_hash(name, options = {})
[name.to_sym, options.values_at(:node, :rel, :labels, :rel_length)].hash
end
|
#association_query_proxy(name, options = {}) ⇒ Object
204
205
206
|
# File 'lib/active_graph/node/has_n.rb', line 204
def association_query_proxy(name, options = {})
self.class.send(:association_query_proxy, name, {start_object: self}.merge!(options))
end
|
#delete_has_one_rel!(rel) ⇒ Object
249
250
251
252
|
# File 'lib/active_graph/node/has_n.rb', line 249
def delete_has_one_rel!(rel)
send("#{rel.name}", :n, :r, chainable: true).query.delete(:r).exec
association_proxy_cache.clear
end
|
#delete_reverse_has_one_core_rel(association) ⇒ Object
232
233
234
235
|
# File 'lib/active_graph/node/has_n.rb', line 232
def delete_reverse_has_one_core_rel(association)
reverse_assoc = reverse_association(association)
delete_has_one_rel!(reverse_assoc) if reverse_assoc && reverse_assoc.type == :has_one
end
|
#delete_reverse_has_one_relationship(relationship, direction, other_node) ⇒ Object
244
245
246
247
|
# File 'lib/active_graph/node/has_n.rb', line 244
def delete_reverse_has_one_relationship(relationship, direction, other_node)
rel = relationship_corresponding_rel(relationship, direction, other_node.class)
delete_has_one_rel!(rel.last) if rel && rel.last.type == :has_one
end
|
#relationship_corresponding_rel(relationship, direction, target_class) ⇒ Object
254
255
256
257
258
259
260
261
|
# File 'lib/active_graph/node/has_n.rb', line 254
def relationship_corresponding_rel(relationship, direction, target_class)
self.class.associations.find do |_key, assoc|
assoc.direction == direction && (
assoc.relationship_class_name == relationship.class.name ||
(assoc.relationship_type == relationship.type.to_sym && assoc.target_class == target_class)
)
end
end
|
#reverse_association(association) ⇒ Object
237
238
239
240
241
242
|
# File 'lib/active_graph/node/has_n.rb', line 237
def reverse_association(association)
reverse_assoc = self.class.associations.find do |_key, assoc|
association.inverse_of?(assoc) || assoc.inverse_of?(association)
end
reverse_assoc && reverse_assoc.last
end
|