-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
Hi all,
Using Bottle and Macaron, I try to implement a kind of sponsorship with a self-jointure on the sql table 'user'
CREATE TABLE "user" (
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ,
"pseudo" TEXT NOT NULL,
"sponsor_id" INTEGER REFERENCES user (id) NOT NULL
);The Macaron implementation should be :
class User (macaron.Model):
pseudo = macaron.CharField( max_length=32 )
sponsor_id = macaron.IntegerField()
sponsor = macaron.ManyToOne( User, fkey="sponsor_id", ref_key="id", related_name="godchildren", on_delete="SET NULL", on_update="CASCADE" )But Traceback returns : NameError: name 'User' is not defined
So, I implement User.sponsor outside the class definition :
User.sponsor = macaron.ManyToOne( User, fkey="sponsor_id", ref_key="id", related_name="godchildren", on_delete="SET NULL", on_update="CASCADE" )It works well when I ask : User.get(id).sponsor
But not on : User.get(id).godchildren where I get the Exception : AttributeError("'User' object has no attribute 'godchildren'")
Is it the right way to implement such a jointure ? Is it a bug ? A limitation ?
Thanks in advance.
Have a good year.
Metadata
Metadata
Assignees
Labels
No labels