Commit 2994695
fix(api): default option type to choice for non-grid questions (#3504)
* fix(api): default option type to choice for non-grid questions
Creating an option through POST .../questions/{id}/options without an
optionType stored the option with a null type. Such options are saved
but never rendered, so the question shows up with no selectable answers.
The option_type migration (Version050300Date20250914000000) already
backfills null types to 'choice', and DataStructure.md documents 'choice'
as the default for normal option lists. newOption() just never applied
that default to new inserts.
Default optionType to 'choice' for any non-grid question when the caller
omits it. Grid questions are left untouched, as their options require an
explicit row/column type. Adds the missing Option::OPTION_TYPE_CHOICE
constant alongside the existing row/column ones.
Signed-off-by: Josef Behr <code@josef-behr.de>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix(api): apply option-type default after ordering lookup
Addresses review feedback on the placement of the default.
Moving the default before findByQuestion() changed the ordering: the
lookup filters by option type, so a freshly defaulted 'choice' no longer
matched existing options that predate the option_type migration (or were
inserted without a type), resetting the order to 1.
Apply the default after the ordering lookup instead. findByQuestion()
keeps the caller-provided type (null means "all options of the question"),
so option order is unchanged, and the inserted option still gets 'choice'.
Signed-off-by: Josef Behr <code@josef-behr.de>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix(api): default option_type via column default and migration
Follow-up to review: move the default out of the controller logic and
into the schema, as suggested.
- New migration gives the option_type column a 'choice' default and
backfills rows still stored without a type.
- newOption() no longer writes an explicit null, so the column default
applies for normal option lists, and re-reads the inserted option so
the response reflects the stored value.
- Grid options are unaffected, as callers always pass an explicit
row/column type.
Removes the earlier controller-side default and the OPTION_TYPE_CHOICE
constant. Integration fixtures now receive 'choice' from the column
default, so the affected expectations are updated.
Signed-off-by: Josef Behr <code@josef-behr.de>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix(api): apply review suggestions for option_type default
- Set the newOption() signature default to 'choice' instead of resolving
it in the method body, now that the migration guarantees stored options
carry a type.
- Drop the explicit-null guard and the post-insert re-read; they are no
longer needed with the signature default in place.
- Return early from the migration schema change when nothing is altered.
- Document the 'choice' default on the optionType parameter.
Signed-off-by: Josef Behr <code@josef-behr.de>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* chore(openapi): regenerate for option_type default change
Reflects the 'choice' default now declared on the newOption optionType
parameter. The reorder-options parameter is unchanged.
Signed-off-by: Josef Behr <code@josef-behr.de>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Signed-off-by: Josef Behr <code@josef-behr.de>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 3a0eacb commit 2994695
4 files changed
Lines changed: 77 additions & 8 deletions
File tree
- lib
- Controller
- Migration
- tests/Integration/Api
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
894 | 894 | | |
895 | 895 | | |
896 | 896 | | |
897 | | - | |
| 897 | + | |
898 | 898 | | |
899 | 899 | | |
900 | 900 | | |
| |||
908 | 908 | | |
909 | 909 | | |
910 | 910 | | |
911 | | - | |
| 911 | + | |
912 | 912 | | |
913 | 913 | | |
914 | 914 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2702 | 2702 | | |
2703 | 2703 | | |
2704 | 2704 | | |
2705 | | - | |
2706 | | - | |
| 2705 | + | |
| 2706 | + | |
2707 | 2707 | | |
2708 | 2708 | | |
2709 | 2709 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
497 | 497 | | |
498 | 498 | | |
499 | 499 | | |
500 | | - | |
| 500 | + | |
501 | 501 | | |
502 | 502 | | |
503 | 503 | | |
504 | 504 | | |
505 | | - | |
| 505 | + | |
506 | 506 | | |
507 | 507 | | |
508 | 508 | | |
509 | 509 | | |
510 | | - | |
| 510 | + | |
511 | 511 | | |
512 | 512 | | |
513 | 513 | | |
| |||
1027 | 1027 | | |
1028 | 1028 | | |
1029 | 1029 | | |
1030 | | - | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
1031 | 1033 | | |
1032 | 1034 | | |
1033 | 1035 | | |
| |||
0 commit comments