FK to self

34 views
Skip to first unread message

otop...@gmail.com

unread,
Aug 1, 2014, 5:03:25 AM8/1/14
to qdj...@googlegroups.com
Is it possible to have model which references itself through foreign key?
In django there is setForeignKey("self"), but I dont see that kind of method in QDjango.

When I run my app then stack overflows because of recursive call to constructor..

class Dirindex : public QDjangoModel
{
    Q_OBJECT
    Q_PROPERTY
(Dirindex *parent READ parent WRITE setParent)
...
}

Dirindex::Dirindex(QObject *parent)
   
: QDjangoModel(parent)
{
    setForeignKey
("dirindex", new Dirindex(this));
}

I worked around this by declaring parent as int - but then I have to implement "on delete cascade" etc..

Maybe if setForeignKey would accept (at least) this format:

setForeignKey("self", 0)

I've read somewhere that the foreign key implementation does not allow this - is this still the case?

Reply all
Reply to author
Forward
0 new messages