Navigations table column:
NULL, 1, 2
I need to do a unique validation for two table. When I save, my records are saved in both tables at the same time.
Unique insert: (
site_id = table
language_id, slug = table
Is it possible to validate between two tables?
Please would not be an example, it is not entirely clear to me from the documentation.
Before sample code would be presented, it would be best to understand what you’re trying to do.
How are you currently posting 2 records into 2 tables at the same time? Wouldn’t
Navigations be posted first? Otherwise how could you get the value for
navigation_id in the
Would it be more correct to assume the Navigations record already exists, and its the validation of the navigation_id field in the NavigationsTexts table which requires the validation?
Please explain the situation more clearly, what does at the same time means to you.
Form helper plus patching does this just fine with field names like
site_id = 1
navigations_texts[language_id] = 1
navigations_texts[slug] = '/some-url'
after click save…
$Content = $this->Navigations->newEmptyEntity();
$Content = $this->Navigations->patchEntity($Content, $this->request->getData());
A new autoincrement ID is created above, in the second table, the new id is copied to
Validation is performed during patchentity and here I would need to verify that the same string no longer exists in the slug column if
site_id = 1 is in table 1.
id, navigation_id, language_id, slug
1, 1, 1, '/some-url'
If I enter the same URL with
site_id = 1, it will throw me an error, because the record already exists. If I choose
site_id = 2, the record can be saved.