Foreign Keys generated as NOCHECK

60 Views Asked by At

According this documentation page (Association Relationship), it seems that CodeFluent Entities generate Foreign keys in NOCHECK mode by default on One to Many and Many to Many relations. On the other hand, the Foreign keys on One to One relations are created in CHECK mode. I have several questions about that:

  • My understanding is that NOCHECK foreign keys are disabled. If so, what is the purpose of creating all that disabled foreign keys ?
  • Is there a way (and an interest) to change that behaviour?
  • We have some One to One relations on our application but still, all the foreign keys are disabled on our database. Why is it so ?

thanks by advance.

1

There are 1 best solutions below

1
On

The foreign keys gives you some informations about the scheme even if there are not enforced. Also it can be convenient during development to not get integrity errors when you update the database. In the documentation, it is said that it's for performance reasons, but I'm really not sure about this one.

Anyway, you can instruct CodeFluent Entities to check constraint by setting defaultPersistenceEnforce="true" on the project

<cf:project defaultPersistenceEnforce="true">

From the documentation

Note: By default referential integrity is not enforced for performance reasons. However, one can enable relationships enforcement globally by setting the defaultPersistenceEnforce attribute of the project node to true.

It's also possible to enforce a specific relationship instead of the whole project. One can do so by specifying the persistenceEnforce attribute to true on the relation property.