You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.
But making generated columns non-nullable provides robust and flexible constraints.
Example
Goals
We have members table and plans table
members.role takes one of ownerguestsubscriber
members.plan_id has value only when members.role is subscriber
We also need to sort members in ownerguestsubscriber order.
Code
$table
->unsignedTinyInteger('sort_priority')
->storedAsNotNull("
CASE WHEN role = 'owner' AND plan_id IS NULL THEN 1 WHEN role = 'guest' AND plan_id IS NULL THEN 2 WHEN role = 'subscriber' AND plan_id IS NOT NULL THEN 3 ELSE NULL END
")
->index();
members.sort_priority allows us making fast sorting ORDER BY sort_priority, id ensuring strong consistency.
The text was updated successfully, but these errors were encountered:
Backward Compatible: Add storedAsNotNull and virtualAsNotNull
Breaking Change: Make storedAs and virtualAs not null by default and accept nullable call
mpyw
changed the title
Add schema method storedAsNotNull and virtualAsNotNull
[Proposal] Add schema method storedAsNotNull and virtualAsNotNullJun 9, 2018
Currently
->storedAs()
and->virtualAs()
always make them nullable.https://github.com/laravel/framework/blob/1cbb54e9da52d66bc09e181c34520df283bf46cd/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php#L892-L897
But making generated columns non-nullable provides robust and flexible constraints.
Example
Goals
members
table andplans
tablemembers.role
takes one ofowner
guest
subscriber
members.plan_id
has value only whenmembers.role
issubscriber
owner
guest
subscriber
order.Code
members.sort_priority
allows us making fast sortingORDER BY sort_priority, id
ensuring strong consistency.The text was updated successfully, but these errors were encountered: