Auto-increment field

Post Reply
User avatar
kubera
Posts: 94
Joined: 01 Feb 2018, 14:42
Name: kubera
Location: Poland

Auto-increment field

Post by kubera »

Hi
I think that this type of field works inperfect. When the entity has no records field in form has empty value.
autoinc_3.jpg

After saving first record (with empty value in auto-inc field) next record will be calculated as '1'
autoinc_2.jpg
In this case there will be hole in auto-increment column.
autoinc_3.jpg
I think that system should sets '1' for first record in entity.
Attachments
autoinc_3.jpg
autoinc_2.jpg
autoinc_2.jpg
autoinc_1.jpg
User avatar
support
Site Admin
Posts: 6222
Joined: 19 Oct 2014, 18:22
Name: Sergey Kharchishin
Location: Russia, Evpatoriya

Re: Auto-increment field

Post by support »

Just make this field required if you don't need empty value.
User avatar
kubera
Posts: 94
Joined: 01 Feb 2018, 14:42
Name: kubera
Location: Poland

Re: Auto-increment field

Post by kubera »

I think that the system should propose a value by default. Even if I make this field required, value is not filled.
User avatar
support
Site Admin
Posts: 6222
Joined: 19 Oct 2014, 18:22
Name: Sergey Kharchishin
Location: Russia, Evpatoriya

Re: Auto-increment field

Post by support »

But for first record you can enter default value.
User avatar
kubera
Posts: 94
Joined: 01 Feb 2018, 14:42
Name: kubera
Location: Poland

Re: Auto-increment field

Post by kubera »

Yes but it should be set by default.
User avatar
kubera
Posts: 94
Joined: 01 Feb 2018, 14:42
Name: kubera
Location: Poland

Re: Auto-increment field

Post by kubera »

I fixed this for myself :)
In file
\includes\classes\fieldstypes\fieldtype_auto_increment.php
in line 49 replace

Code: Select all

$check_query = db_query("select (max(field_{$field['id']}+0)+1) as max_value from app_entity_{$field['entities_id']}");
to

Code: Select all

$check_query = db_query("select (COALESCE(max(field_{$field['id']}+0),0)+1) as max_value from app_entity_{$field['entities_id']}");
Post Reply