-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reflection on a table with self-referencing ForeignKey does not complete #297
Comments
I will fix this recursive problem but i wonder if this is a valid scenario. |
Thanks @AliSayyah! The scenario that I'm trying to capture in this data modeling is when there's an unknown number of parent entities and child entities. To keep the schema flexible, it's kept in a long table format. For example, this could be useful in a growing organization tree and mapping out which employee reports to another employee (whom might report to someone else). I'm no data modeling expert, so I'm very open to other models that might cover this type of scenario. |
@knguyen5 that makes sense to me. I don't have any alternative to suggest but i think @dantownsend can help more in this matter. |
I've used recursive foreign keys a few times in the past. Things like this are quite common: class Employee(Table):
name = Varchar(length=100)
manager = ForeignKey(references='self') It should be possible to support this in |
I think this should be a pretty straightforward fix. Postgres doesn't have any special syntax for self-referencing tables, so far as I can tell, literally just the table name itself, like any other. So if when parsing the table meta we find that a FK column refers to the same table it is defined on (a simple equality check), this should be reflected by Piccolo's |
@wmshort yes that should work. |
I'll make a PR as soon as I can get to this, sorry for delay |
Fixed by #305 |
👍 |
When running a reflection on a table that includes a self-referencing ForeignKey, such as the example below, the process hangs or never completes:
After removing the foreign key or replacing with another table reference, the reflection completes as expected.
The text was updated successfully, but these errors were encountered: