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

Inconsistent results for has_many relation each_rel/rels #1696

Open
petergebala opened this issue May 16, 2023 · 2 comments
Open

Inconsistent results for has_many relation each_rel/rels #1696

petergebala opened this issue May 16, 2023 · 2 comments

Comments

@petergebala
Copy link

petergebala commented May 16, 2023

Looks like calling each_rel or rels affects the relation and removes objects from it.

Previously we were using:
Neo4j database version: 4.4
ActiveGraph version: 11.1.0.alpha.4
Neo4j-driver-ruby: 4.4.3

Code below was working as expected.

Now we try to upgrade gem versions to:
Neo4j database version: 4.4
ActiveGraph version: 11.3.1
Neo4j-driver-ruby: 4.4.4

Code example (inline, gist, or repo)

class Skill
  # ...
  has_many :out, :categories, model_class: :SkillCategory, rel_class: :SkillInCategory 
  # ...
end

class SkillCategory < Category
  has_many :in, :contents, model_class: :Skill, rel_class: :SkillInCategory
end

# Later we have test to check if we create uniq relations:
skill.categories << skill_category
skill.categories << skill_category
skill.categories << skill_category

skill.categories.each_rel.count == 1
skill.categories == [skill_category] # Fails, skill.categories relation is empty.
# Problem is with the order of the operations. Looks like calling `each_rel` replaces skill_categories with empty array.
# Real output from console:
[13] pry(#<RSpec::ExampleGroups::Skill::UniqueCategories>)> skill.categories
=> #<AssociationProxy Skill#categories [#<SkillCategory _global_id: "test-skill-category_1000001", _source_id: "1000001", _source_type: "test-skill-category", description: nil, name: "Organized systemic analyzer">]>
[14] pry(#<RSpec::ExampleGroups::Skill::UniqueCategories>)> skill.categories.each_rel.size
=> 1
[15] pry(#<RSpec::ExampleGroups::Skill::UniqueCategories>)> skill.categories
=> #<AssociationProxy Skill#categories []>
[16] pry(#<RSpec::ExampleGroups::Skill::UniqueCategories>)> skill.reload
=> #<Skill _global_id: "test-skill_1000001", _source_id: "1000001", _source_type: "test-skill", name: "Integrated Contextually-Based Ability">
[17] pry(#<RSpec::ExampleGroups::Skill::UniqueCategories>)> skill.categories
=> #<AssociationProxy Skill#categories [#<SkillCategory _global_id: "test-skill-category_1000001", _source_id: "1000001", _source_type: "test-skill-category", description: nil, name: "Organized systemic analyzer">]>
[18] pry(#<RSpec::ExampleGroups::Skill::UniqueCategories>)> skill.categories.rels.size
=> 1
[19] pry(#<RSpec::ExampleGroups::Skill::UniqueCategories>)> skill.categories
=> #<AssociationProxy Skill#categories []>
@klobuczek
Copy link
Member

@petergebala One immediate issue I see is the usage of

... rel_class: :SkillInCategory 

If you need a rel_class, because it has some properties you cannot do:

skill.categories << skill_category

You need to create the relationship object with its start, end node, and properties.
Maybe you don't need the rel_class.

Your ticket is still probably valid though.

@petergebala
Copy link
Author

Yes. Relation doesn't have any property. Thanks for tip. Issue is still there

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

No branches or pull requests

2 participants