MetaModels / core

MetaModels Core Module
GNU Lesser General Public License v3.0
95 stars 42 forks source link

Referenced Meta Models with brackets ( ... ) can not be chosen (Error: did not accept the value) #1501

Closed amenk closed 1 year ago

amenk commented 1 year ago

Checklist before I submit this issue report

I confirm that:

My environment is:

(Please fill in the actual values from your environment - check Contao Manager or use composer show)

Key Value Comments
PHP version: 8.1
Contao version: 4.13
MetaModels version: 2.3@dev
Installed MetaModels packages: almost all
DCG version: 2.3@dev

Issue description

When selecting a metamodel reference which contains ( ) in the field name, it is not accepted.

Steps to reproduce

  1. Have to metamodels, one (A) references to another (B)
  2. in B create an entry with the Name "Frankfurt (Oder)"
  3. Reference field is the name
  4. Choose the new entry in A

Describe the behaviour of the application

Message:

Ungültige Auswahl!
Property vita_location (select) did not accept the value (The values differ. Encountered type NULL expected string (Found NULL, expected 'Frankfurt (Oder)')).

Describe the expected behaviour of the application

The form can be saved

Workaround

Rename the entry to "Frankfurt - Oder" and chose it.

Also it might be possible to use the id field as reference instead of the name, but I guess we would need to migrate the references then?

Screenshots

image image

Context

We have this in a Migration project from Countao 4.3 with an older Metamodels version. The data was copied to the new instance - so this might have worked in the older version of Contao / Metamodels.

zonky2 commented 1 year ago

@amenk Could you check the DB to see how "Frankfurt (Oder)" was saved - as entered or encoded?

Is it possible to select a real alias column for alias as well? It seems to be a MM table...

Is the relation table also multilingual and is "partner_name" multilingual?

amenk commented 1 year ago

@zonky2

1) It's saved in encoded form Frankfurt (Oder) 2) Yes it's a MM table -- my first thought was to select the alias or ID as well. But wouldn't we need to migrate the existing relations or does this happen automatically? - also I was not sure if this is an intended limitation and a field like name should just not be possible to use as relation. 3) Nothing seems to be multilanguage

amenk commented 1 year ago

Re 2) If I select "id" as the alias column (we don't have an alias) that would work, yes

zonky2 commented 1 year ago

You should always create an alias for relations - e.g. to have clean URL parameters for filtering.

I assume that the problem is with the encoding - I'll have to create a test case.

You can check this to change Frankfurt (Oder) to Frankfurt (Oder) directly in DB

amenk commented 1 year ago

okay, good to know - while I think we don't have filters on this field anyways.

When changing it in the database it does not help - same error. Also in the Backend Form it selects the first entry after we get the error.

zonky2 commented 1 year ago

hmm... o.k. - I can can check this after create a test case....

Background info: we have two methods widgetToValue and valueToWidget - when saving, the widgetToValue is executed first to check the value and then the valueToWidget - if the value is the same as the initial value, only then is it saved to the DB - otherwise the error message shown comes up.

zonky2 commented 1 year ago

The problem is that Contao automatically changes the text when saving it to the database - so Frankfurt (Oder) becomes Frankfurt (Oder)

The conversion can be switched off in the settings of the attribute of the input mask, so that Frankfurt (Oder) is saved in the DB.

In MM B, however, we cannot determine which setting was selected for MM A in the input mask or whether there were other conversions.

As written, an alias attribute should also be selected for Alias...

In MM we can't solve the problem - in the future the conversion before storing in the DB from Contao will be omitted - we welcome this very much and hope the "feature" will come in Contao 5

amenk commented 1 year ago

The conversion can be switched off in the settings of the attribute of the input mask, so that Frankfurt (Oder) is saved in the DB.

I tried to find such a setting in table=tl_metamodel_dcasetting&id=tl_metamodel_dcasetting of MM A.

image

But I guess, there just is no other solution than creating an alias for now? I think I misunderstood the answer first :-) I think we will just create an alias.

zonky2 commented 1 year ago

Go to your related "MM B" and open the attribute "name" at input mask...

grafik

save your item with name Frankfurt (Oder) and check the value at DB

amenk commented 1 year ago

save your item with name Frankfurt (Oder) and check the value at DB

Perfect, works :-)