question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Return correct subclass from relationship

See original GitHub issue

I have a model with this design: Gene is located on either Chromosome or Contig. At the moment I’m solving this in the model by creating a class Feature from which both Chromosome and Contig inherit. The RelationshipTo is restricted to specifying a single class, so node I have code similar to:

class Feature(StructuredNode):
    name = StringProperty()
    location = RelationshipTo('Feature', 'LOCATED_ON', cardinality=One)

class Gene(Feature):
    description = StringProperty()

class Chromosome(Feature):
    pass

class Contig(Feature):
    pass

In the real model, Contig and Chromosome have different attributes. The problems that arise with this model are that:

  1. A spurious label (Feature) is introduced into the database.
  2. When querying for location (gene.location.all()) a Feature is returned, not the actual Chromosome or Contig that the gene is located on.

Inside the code the correct label is identified during querying but the actual object returned is of the superclass.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
robinedwardscommented, Aug 4, 2017

Hey apologies my brain wasn’t in gear yesterday.

We need to be a little bit careful as I think there is some existing functionality built around assuming abstract nodes dont have labels… However your case above (relation to abstract node) should definitely raise a friendly error message in the current release of neomodel.

What you are trying to achieve is quite similar to #126

Now I am not opposed to changing the behaviour of inheritance in a major release of neomodel, the current situation is confusing at best. In fact the whole handling of ‘abstract nodes’ is hacky and unpythonic. One issue with the subclass behaviour is when someone wants to build a model which actually points to the super class (none abstract) it becomes tricky.

0reactions
aanastasioucommented, Mar 7, 2019

@pvanheus Can I please ask if you have tried version 3.3.1? The changes there would cover this use-case I wonder if this would be enough to close this issue (?).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Subclassing and Inheritance - Learning Java, 4th Edition [Book]
A subclass inherits variables and methods from its superclass and can use them as if they were declared within the subclass itself:
Read more >
Inheritance (IS-A) vs. Composition (HAS-A) Relationship
You can't add to a subclass a method with the same signature but a different return type as a method inherited from a...
Read more >
Table per subclass inheritance relationship: How to query ...
A workaround is described below: Define your Parent class as MappedSuperClass. Let's suppose the parent class is mapped To PARENT_TABLE
Read more >
Inheritance Relationship - an overview | ScienceDirect Topics
Inherited operations reside in the superclass; subclasses do not need to carry around their own version, unless they are going to specialize the...
Read more >
Describing Property Relationships - Apple Developer
Class descriptions provide a method of describing the to-one and to-many properties in a class. Defining these relationships between class ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found