XF 2.2 table constraints

briansol

Well-known member
is there a recommendation on FK constraints?

i don't see a method in
XF\Db\Schema\Alter to add in a FK constraint.

That tells me it likely isn't something others are using.

what's the best practice?
 
Foreign key constraints are not something we have ever used with XF so you’re right, others generally aren’t using them and we have no particular plan to.

For the situations where foreign key constraints may be useful, there are various things built into the Entity system that may help replicate a similar behaviour.

Such as you can add code to detect an invalid value being inserted and prevent saving an entity. The benefit there being you could display a clearer error, or even decide not to display an error at all and just discard the value (we do this if you try to set an invalid prefix_id for a thread - we just set it to 0).
 
Top Bottom