Skip to content

Problem in auto-jointure #45

Description

@FrViPofm

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions