Skip to content

QueryProxy replace_with compares IDs globally, instead of per model-class #1653

Open
@yourpalal

Description

@yourpalal

While investigating #1652, I noticed that QueryProxy replace_with compares IDs for all models to determine which relationships to delete and insert.

Assuming the id in question is a uuid, this probably works out fine, but when using multiple model classes, there could be some overlap of ids between the two model classes.

Note: the problem in the example below is currently hidden by the bug reported in #1652 . If pluck(:id) is were fixed, but no other changes were applied, then #1652 could be considered fixed, while this issue would not be.

Probably the best course of action is to fix this and #1652 at the same time.

Code example (inline, gist, or repo)

class Book
  include ActiveGraph::Node
  
  id_property :isbn
  
  has_one :in, :publisher, origin: :published_things, model_class: %w(Publisher)
end

class Magazine
  include ActiveGraph::Node
  
  id_property :issue_id
  
  has_one :in, :publisher, origin: :published_things, model_class: %w(Publisher)
end

class Publisher
  include ActiveGraph::Node
  
  has_many :out, :published_things, type: :published, model_class: %w(Book Magazine)
end

original_zine, book = [ Magazine.create!(issue_id: "1234"), Book.create!(isbn: "098512=25") ]
publisher = Publisher.create!
publisher.published_things = [original_zine, book]

replacement_zine = Magazine.create!(issue_id: "098512=25") # same as book isbn
publisher.published_things = [replacement_zine] # leads to replace_with being called

# replacement_zine did not get a rel, since it has the same id as book
replacement_zine.reload
puts replacement.publisher # puts nil

# book was not removed, since it has the same id as replacement_zine
book.reload
puts book.publisher # puts non-nil

Runtime information:

Neo4j database version:
neo4j gem version: 10.1.0
neo4j-ruby-driver gem version: 1.7.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions