Module: Neo4j::ActiveNode::HasN
- Extended by:
- ActiveSupport::Concern
- Included in:
- Neo4j::ActiveNode
- Defined in:
- lib/neo4j/active_node/has_n.rb,
lib/neo4j/active_node/has_n/association.rb,
lib/neo4j/active_node/has_n/association/rel_factory.rb,
lib/neo4j/active_node/has_n/association_cypher_methods.rb
Defined Under Namespace
Modules: AssociationCypherMethods, ClassMethods Classes: Association, AssociationProxy, NonPersistedNodeError
Instance Method Summary collapse
- #association_proxy(name, options = {}) ⇒ Object
-
#association_proxy_cache ⇒ Object
Returns the current AssociationProxy cache for the association cache.
- #association_proxy_cache_fetch(key) ⇒ Object
- #association_proxy_hash(name, options = {}) ⇒ Object
- #association_query_proxy(name, options = {}) ⇒ Object
Methods included from ActiveSupport::Concern
Instance Method Details
#association_proxy(name, options = {}) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/neo4j/active_node/has_n.rb', line 178 def association_proxy(name, = {}) name = name.to_sym hash = association_proxy_hash(name, ) 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, .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, ) 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
159 160 161 |
# File 'lib/neo4j/active_node/has_n.rb', line 159 def association_proxy_cache @association_proxy_cache ||= {} end |
#association_proxy_cache_fetch(key) ⇒ Object
163 164 165 166 167 168 |
# File 'lib/neo4j/active_node/has_n.rb', line 163 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
174 175 176 |
# File 'lib/neo4j/active_node/has_n.rb', line 174 def association_proxy_hash(name, = {}) [name.to_sym, .values_at(:node, :rel, :labels, :rel_length)].hash end |
#association_query_proxy(name, options = {}) ⇒ Object
170 171 172 |
# File 'lib/neo4j/active_node/has_n.rb', line 170 def association_query_proxy(name, = {}) self.class.send(:association_query_proxy, name, {start_object: self}.merge!()) end |