Skip to content
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

Relational query in wrong order #1611

Closed
shu-bc opened this issue Jul 15, 2020 · 3 comments · Fixed by #1612
Closed

Relational query in wrong order #1611

shu-bc opened this issue Jul 15, 2020 · 3 comments · Fixed by #1612
Labels

Comments

@shu-bc
Copy link

shu-bc commented Jul 15, 2020

Suppose a book model has_many pages like this

class Book
  has_many :out, :pages, type: :has, model_class: :Page
end

book.page_ids can return an array of unique ids of related pages instances
book.page_ids = [....]; book.save is supposed to update its relation, as it does in v9.x.

But in v10.0, this doesn't work, since it will issue delete queries that delete existing relation only AFTER issuing create queries.
This causes trouble if some id in the array is included in the existing relations.
In an extreme case, if you pass the exact same id array, then this will completely destroy existing relations.

This can be solved by just reversing the order of relational queries.

Additional information which could be helpful if relevant to your issue:

Code example (inline, gist, or repo)

Runtime information:

Neo4j database version: neo4j 3.4.0
neo4j gem version: v10.0
neo4j-core gem version:

@klobuczek
Copy link
Member

@shu-bc it would be always helpful to have a complete spec. Are you saying that this spec will fail?

it 'does not delete pages on reassignment` do
  page = Page.create
  book = Book.create(pages: page)
  book.page_ids = [page.id]
  book.save
  expect(book.pages).to be_present
end

@amitsuryavanshi
Copy link
Member

Confirming that, this is a issue. If you have a non integer id_property you get this issue. Thanks for reporting @shu-bc, we are on it.

@shu-bc
Copy link
Author

shu-bc commented Jul 15, 2020

@klobuczek yes, exactly.

@amitsuryavanshi oh yes, that is the case. Our id is created by SecureRandom.uuid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants