delete_instance with recursive=True only works with one level
Oh, yeah - I don't think it correctly handles foreign-keys to self. The best way is to lean on your database to handle this with an `on_delete=...` in your `ForeignKeyField()` declaration. @coleifer Oh, so what's the purpose of recursive flag, it only works for 1 level?

https://github.com/coleifer/flask-peewee/issues/31
I've read this post and thought peewee can do delete recursively.

Self-reference is needed to be use on multiple level items like categories, posts.
I use mysql, so any other way to do delete recursively? Or i have to override `delete` method to implement it myself? If you have a row with a deep dependency graph of foreign-keys, it will correctly handle dependent rows without leaving orphaned data. That is the purpose.

The reason it does not support hierarchical data (i.e. self-referential foreign-keys) is to avoid cycles in the dependency graph.

> I use mysql

Doesn't innodb support ON DELETE constraints? > avoid cycles in the dependency graph.

Can we check the type of foreign key before deleting, it would avoid circular delete?
I prefer to do delete on code rather than depend on db.



 I remembered that the other - in fact, main - reason for not supporting this is that we don't know how *deep* into the graph to go without resolving foreign-keys at every step.

So with a non-self-referential graph of foreign-keys, we just make sure to issue a query for each node in the graph (each foreign-key). With self-referential, we would have to issue *n* deletes where *n* is the maximum depth of any row's relations. But we don't know how far to go without resolving at each step. So peewee doesn't do this, but you could very easily write it yourself.

Or just use the database. The database knows how to delete a self-referential collection of rows. That is why the `ON DELETE` constraint exists. Use it!

> I prefer to do delete on code rather than depend on db.

Why? To my thinking that's 100% backwards.
I have a table with foreign key to itself

```
class Post(BaseModel):
    reply_to: Post = ForeignKeyField(
        'self', null=True, default=None, backref='child_posts', on_delete='CASCADE')
```

Then in db if i have
```
id reply_to_id
1 nulll
2 1
3 2
4 3
5 4
```
If i `delete_instance(True, True)` record `id=2`, it deletes ID `2,3` only and leave ID `4,5`.
It means it doesn't delete recursively (only works for 1 level).

Did i miss something or i have to deploy delete recursively by myself?