Inverted `ModelAttribute`
Today when two models reference each other, we use this trick to have only one index:
class Foo(sheraf.Model):
table = "foos"
bar = sheraf.ModelAttribute("Bar").index()
class Bar(sheraf.Model):
table = "bars"
@property
def foo(self):
return Foo.search(bar=self)
@foo.setter
def foo(self, value):
value.bar = self
We should provide an attribute that does this automatically:
class Foo(sheraf.Model):
table = "foos"
bar = sheraf.ModelAttribute("Bar").index()
class Bar(sheraf.Model):
table = "bars"
foo = sheraf.InvertModelAttribute("Foo.bar")
We expect:
- This attribute to only work if
Foo.baris indexed - Deletion the
Barobject inFoo.barwhen theBarobject is deleted. - This deletion trick should also work for
LargeListAttribute(ModelAttribute(Bar)) -
Bar.fooshould be settable -
Bar.createshould be able to take afooargument
Edited by Éloi Rivard