Foreign Key?

  • Hey,


    in one of my projekts i have a lot of tables.
    Some of them are related to each other.

    For example i have following entities:


    product, productCategory, package, package_productCategory


    An product can have one productCategory. An Package can contains multiple productCategories.


    Now it's important to avoid dropping a productCategory, that's used in product or/and productCategories.


    How would you do this? Should i use foreignKeys, or should i hook in the @deleting event from doctrine?

  • How would you do this? Should i use foreignKeys, or should i hook in the @deleting event from doctrine?

    So if I understood correctly, you would like to avoid to delete a productCategory, while it's being used by another package, right?


    So I think you can easily do that with @delete annotation. On this event, check, if productCategory is assigned to another package. Using Many-To-Many, you could easily check the result of related('foo').

  • Quote

    So if I understood correctly, you would like to avoid to delete a productCategory, while it's being used by another package, right?

    Yes, but i also like to avoid deleting when it's used in product too...
    That's only an example.. there are a lot of other tables where productCategoryis used.


    Do'nt you think it's better to use ForeignKeys to check relations?

  • That's only an example.. there are a lot of other tables where productCategoryis used.


    Well - in this case I would check, if there's a possibility to check, whether productCategory is used somewhere, not on @delete-event of Package or Product, but on @delete event of ProductCategory.


    Not sure, if you can still stop deleting then, but I'd check that.


    Of course you can do it using foreign keys, but I prefer the methods the ORM comes with. I prefer this, because I think it's easier to understand, even if you did not work on this extension for months. But of course it's possible that you don't think this way ;)

  • Maybey you can post here how to stop deleting in case of existing usages


    Well - I am not sure, whether this is possible. I did not do that before.


    As soon as I find some time, I will check that. Maybe other users ( Tobbe knows a lot about Pagekit's core) can tell something in the meantime.

  • As i can see, App:abort() will only support these Codes: