php-crud-api icon indicating copy to clipboard operation
php-crud-api copied to clipboard

PK/FK detection "by convention" as a fallback

Open mevdschee opened this issue 9 years ago • 3 comments

To support PK and FK in MyISAM and views the key "detection" could fall back to "by convention", which requires you to name the PK "id" and the FK as the full table name followed by "_id".

mevdschee avatar Sep 11 '16 12:09 mevdschee

This works for me, so hope you can add it in at some point. I always have a PK of 'ID' on every table as I believe it to be a good practice when using hybrid data records.

pottertech avatar Sep 11 '16 16:09 pottertech

Another method would be do define the pk and fk relationships in the config as proposed in #482.

mevdschee avatar Feb 24 '19 08:02 mevdschee

Let's say a database has tables 'post' and 'user' and table 'post' has a field 'author_user_id' then we could use '_id' as a signal that it is a FK (always to field 'id') and the word before that should be the table that is referred to 'user', the first part is optional and is the name of the field (defaults to the table name).

mevdschee avatar Oct 04 '20 05:10 mevdschee