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

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/neo4j/active_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_cacheObject

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/neo4j/active_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/neo4j/active_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/neo4j/active_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/neo4j/active_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