-
Notifications
You must be signed in to change notification settings - Fork 274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Node must be of the association's class when model is specified? #717
Comments
Try doing a bundle update on neo4j and neo4j-core if you haven't already, On Wednesday, March 11, 2015, Burak Arikan [email protected] wrote:
|
Thanks, just attempted to do an update, already have the latest.
Currently looking into it, let you know if I find more hints. |
Trying to debug this problem, but no chance. One thing clear however, that, the error is caused by the change in the declared relation naming with Neo4jrb 4.1. I tried the "legacy" as well as the new relation naming scheme, it both throws the same error. config.neo4j.transform_rel_type = :legacy
One interesting case: If I restart the server, it works for the first time, then keeps throwing the error above for the rest of the attempts. |
What version were you using before? The change has an impact on relationship types but not the logic that determines whether a node is of the appropriate class to create the relationship. |
We upgraded to version 4.1 from version 3.x. As mentioned above, the invitation instance of the Invitation Model to associate (user.invitation = invitation) is clearly there, but it throws this "not appropriate" error, except when I restart the server, exact same association code works for the first time, and stops working in the following attempts... which is really weird. |
So, I ended up creating the declared relation like an undeclared relation, which worked fine: @user.create_rel('#received_invitation', @invitation) However, the problem with association below remains: @user.received_invitation = @invitation
# ArgumentError - Node must be of the association's class when model is specified: Also note that I use |
If you successfully create the relationship, does |
Yes |
This error However, using a relation name different than the associating model and referencing with class User
has_many :out, :sent_invitations, model_class: Invitation
has_one :out, :received_invitation, model_class: Invitation
class Invitation
has_one :in, :sender, model_class: User, origin: :sent_invitations
has_one :in, :recipient, model_class: User, origin: :received_invitation
# these work without errors
@invitation.sender = current_user # or current_user.sent_invitations << @invitation
@user.received_invitation = @invitation # or @invitation.recipient = @user But, if I use the model name for relation and do not use class User
has_many :out, :invitations
class Invitation
has_one :in, :sender, model_class: User
current_user.invitations << @invitation
# ArgumentError - Node must be of the association's class when model is specified: |
Well, it turns out the source of the problem is the While creating a relation, there is a check of both model classes here: And, somehow the hub = Hub.find(params[:hub_id])
if hub.is_a?(Hub)
puts "correct type"; puts hub
else
puts "wrong type??"; puts hub
end
# returns:
# wrong type???
# #<Hub:0x007fcfcee56f50>
# thus, this throws error: Node must be of the association's class
hub.nodes << @node Whereas if I do this, it works fine: hub = Hub.first
if hub.is_a?(Hub)
puts "correct type"; puts hub
else
puts "wrong type??"; puts hub
end
# returns:
# correct type
# #<Hub:0x007f8b018bd3f8>
# it works fine here:
hub.nodes << @node Can you take a look at what's wrong with the |
I can't seem to reproduce this. Just added one more test: That passes when I run it. When I test it in my sample app, everything checks out, too.
Can you share the full |
hmm if I try in the console it works fine too. But this happens in the controller context, why would it make any difference? (I am on rails 4.2, not that it makes a difference, jusy fyi.) |
I can't think of any reason. Is it possible that your query is returning |
Nope, the query returns the object, as it prints it in the console, altough it is the wrong type: if hub.is_a?(Hub)
puts "correct type"; puts hub
else
puts "wrong type??"; puts hub
end
# returns:
# wrong type???
# #<Hub:0x007fcfcee56f50> |
What does |
hub = Hub.find(params[:hub])
if hub.is_a?(Hub)
puts "correct type"; puts hub
else
puts "wrong type???"; puts hub
end
puts hub.inspect
# returns:
# wrong type???
# #<Hub:0x007ffe63afd188>
# #<Hub created_at: Tue, 17 Mar 2015 04:42:25 +0000, description: ""... |
So if I restart the server, |
Really weird. I can't think of what would do that. What does |
same thing: ...
puts hub.class
puts hub.class.name
returns:
# wrong type???
# #<Hub:0x007f8218a10e40>
# Hub
# Hub |
If it works for a while and stops, my feeling is that another model or class is being loaded at some point that's redefining a method used by the gem. Any chance you can look for something like this? |
Would that be the Devise gem? Almost all our model's controllers have the authentication.
|
I doubt it, Devise is pretty popular and we've never had this reported. If you do |
I tried |
This still happens in the controller context in my application. It only appears to happen when a file is changed in the application. A restart of the rails server fixes the issues until a file is changed again. When accessing the console from a webview in Rails 4.2 |
Same bug I had today. Also using Devise btw, but temporarily commenting out My unsubstantiated hunch - there's some kind of global logic being used somewhere in the gem, that will overwrite the global used after .find(...) if another one is called, and then some features will stop working? Shrug |
This is fixed in 5.2.x. |
Thanks for everyone's help and patience with troubleshooting! |
While associating one model to another via the simplest declared connection, I've been getting the error below since we upgraded to Neo4j 2.2, Neo4jrb 4.1, Rails 4.2.
Invitation object is clearly there as puts
#<Invitation:0x007ff1a9a1acc8>
The last line tries to make the association with the cypher below, then throws the error above.
This is weird:
Class#invitation#invitation
I don't get what's happening here? Any thoughts?The text was updated successfully, but these errors were encountered: