Laravel and SQL good practices for types

时间:2019-01-18 18:18:49

标签: mysql sql database laravel eloquent

I have a table with "types" that looks like this :

Common, Rare, Mythic, New

and an "item" table that has a type as a foreign key. In fact Common are common to all of types except New. Instead of doing a 0..n relation I wanted to put what's common on all columns except "New"

Is it possible through Laravel Eloquent or is it just a bad practice to try like this?

Thanks you!

1 个答案:

答案 0 :(得分:0)

Following points should be considered about ENUM usage:

ENUMs work best when

  • The type you are representing is local to the table only
  • It must represent a type that is never changed
  • It will never likely experience redefinition
  • Its cardinality needs to be low
  • Its portability must always be based on logical dumps of the table, never physical.

When not to use ENUM

  • When ENUM type is not fixed
  • When ENUM type has a long list of values
  • When your application does not know the list of ENUM values
  • ENUM type is not reusable
  • Portability is a concern

I hope these points will help you.