Return correct subclass from relationship
See original GitHub issueI 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:
- A spurious label (Feature) is introduced into the database.
- When querying for location (
gene.location.all()
) aFeature
is returned, not the actualChromosome
orContig
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:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
@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 (?).