Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make self-referencing default values work #36357

Closed
gioman opened this issue May 11, 2020 · 2 comments
Closed

make self-referencing default values work #36357

gioman opened this issue May 11, 2020 · 2 comments

Comments

@gioman
Copy link
Contributor

gioman commented May 11, 2020

This request comes after #35030 and after a brief exchange with @m-kuhn.

Long story short:

when setting a default value in the properties of a vector layer, the user can use values like "5", or variables (i.e. @username) or functions (i.e. now()) and have this correctly applied on insert and on update (the latter if the proper checkbox is selected).

when using other expressions, i.e. containing field names, QGIS now warns the user with the following message:

"using fields in a default value expression only works if "apply default value on update" is checked"

meaning that the expression will be applied only on update and not on insert.

Is not difficult to create a use case where it make sense to have the default expression to work both for inserts and updates. At the moment if this default option have the "using fields in a default value expression..." checked then it won't work on inserts.

Take a point vector

Create a column "common_name"

Create a column "scientific_name"

Crete a default value for "scientific_name" as following

CASE 
WHEN 
 "common_name" = 'Cork Oak' 
THEN
'Quercus suber'
WHEN 
 "common_name" = 'Eucalypt' 
THEN
'Eucalyptus globulus'
ELSE
'no match'
END

I guess you see the point, is a use case where it make sense have the default expression work for both inserts and updates... a specie can be wrongly defined on insert and then is needed to fix is common and scientific names

Start add points and in the "common_name" field write 'Cork Oak' or 'Eucalypt' , you'll se the "scientific_name" column be filled as expected immediately, but then the computed values are discarded after saving if "using fields in a default value expression..." is checked.

If is not checked it will works for inserts but not for updates.

Peek 2020-05-10 22-08

@gioman
Copy link
Contributor Author

gioman commented May 11, 2020

I have been pointed that with "using fields in a default value expression..." checked it should also work on insert. So maybe it is me or maybe this is not working anymore on master (which I'm using).

#31167

@gioman
Copy link
Contributor Author

gioman commented May 11, 2020

At this point I'm not sure if I'm not using correctly the expressions or if is QGIS, so I'll close until I will have clarified it.

@gioman gioman closed this as completed May 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant