Open adamlwatson opened 5 years ago
Looks like it is only called when finding via the Model.find
method.
https://github.com/neo4jrb/neo4j/blob/f1c3a5bb29d92bbcbe3c948a43f23b35020dc467/lib/neo4j/active_node/labels.rb#L107
Thanks for the reply... looks like you are correct. This seems broken... wondering why the callback wouldn’t be implemented for all find
methods. If it’s a matter of not wanting to evaluate queries prematurely, some sort of hint method, or a standard enumerable call could be added to specify that evaluation should occur.
Anyway, definitely worth a bit of extra documentation to avoid confusion.
It looks like it would be fairly straight forward to make the callbacks fire for find_by
, I noticed that find_by
only return the first match, is that preferred?
def find_by(values)
all.where(values).limit(1).query_as(:n).pluck(:n).first
end
The complete list of methods which should fire the after_find
callbacks:
#all
#first
#find_by
#find_by_*
#find_by_*!
#last
As the title states, the
after_find
ActiveNode callback does not get executed after performing a query that returns a record.Additional information which could be helpful if relevant to your issue:
Code example (inline, gist, or repo)
Test code:
As you can see from the above test code,
after_initialize
is called as expected, butafter_find
is not.Digging through the source, I can see a comment in
neo4j-9.4.0/lib/neo4j/shared/callbacks.rb
on line 12 that states:But when I look at
neo4j-9.4.0/lib/neo4j/active_node/id_property.rb
, it does not look as if any of thefind*
methods are calling theafter_find
callback once their logic is executed.Runtime information:
Neo4j database version:
neo4j
gem version: 9.4.0neo4j-core
gem version: 9.0.0