尤川豪   ·  5年前
445 貼文  ·  275 留言

資料模型的建構方式...

這陣子需要建構不同情境的多種資料模型

  1. 常見 MySQL 的 relational model 自然是最常用的

  2. 然後還有使用 JSON 類型的存法,會得到大量彈性,但失去資料類型,並且資料結構不保證一致

  3. 另外也有 EAV model 的存法。很多汎用型開源系統,如 wordpress、magento 都會大量使用。一樣會得到大量彈性,缺點是資料會四散、不在一處,並且通常會失去資料類型,除非開多張 table 給 EAV model,各自處理一種類型

  4. 還遇到了以上都不適合的情境,開始去看其他幾個東西:

    • Single Table Inheritance
    • Multiple Table Inheritance
    • Class Table Inheritance
    • Polymorphic Associations

Single-Table Inheritance vs Class Table Inheritance

https://pote.io/blog/single-table-inheritance-vs-class-table-inheritance

When To Use Single Table Inheritance vs Multiple Table Inheritance

https://medium.com/@User3141592/when-to-use-single-table-inheritance-vs-multiple-table-inheritance-db7e9733ae2e

Single-table inheritance vs. polymorphic associations in Rails: find what works for you

https://medium.freecodecamp.org/single-table-inheritance-vs-polymorphic-associations-in-rails-af3a07a204f2

How can I implement single table inheritance using Laravel's Eloquent?

https://stackoverflow.com/questions/26691577/how-can-i-implement-single-table-inheritance-using-laravels-eloquent


我發現在設計平台類型的系統時,在不同情境下,可能會需要同時用到以上全部手段。

學習後端工程時,需要對這所有 data modeling 方式都有所了解才行。

(更別提還有 NoSQL 的方式呢!)

  分享   共 1,226 次點閱
按了喜歡:
共有 0 則留言
還沒有人留言。歡迎分享您的觀點、或是疑問。
您的留言
尤川豪
445 貼文  ·  275 留言

Devs.tw 是讓工程師寫筆記、網誌的平台。隨手紀錄、寫作,方便日後搜尋!

歡迎您一起加入寫作與分享的行列!

查看所有文章