基本的に、下の画像は、私が取り組んでいるサイトのホームページのコンポーネントを表しており、いたるところにニュース コンポーネントがあります。SQL のスニペットは、私がどのように機能すべきかを想定していますが、以前にニュース サイトで作業したことのある人からビジネス ロジックに関するアドバイスをいただければ幸いです。これが私がそれをどのように想像するかです:
質問 #1 : SQL ロジックは理にかなっていますか? あなたが見ることができる警告/欠陥はありますか?
私のスキーマは次のようになります。
articles:
article_id int unsigned not null primary key,
article_permalink varchar(100),
article_name varchar(100),
article_snippet text,
article_full text
article_type tinyint(3) default 1
すべての記事 (主な特集、副次的な特集、残り) を 1 つのテーブルに格納type
し、テーブル内の番号に対応する列でそれらを分類しnews_types
ます (この例では、理解しやすいようにリテラル テキストを使用しました) )。
質問 #1.1 : 異なる種類の記事について 1 つのテーブルに依存しても問題ありませんか?
ニュース記事には、次の 3 種類の画像を含めることができます。
- 記事のパーマリンク ページにのみ表示される 1x 元の画像サイズ
- ホームページ セクション #1 に表示される 1x メインのアイキャッチ画像
- ホームページ セクション #2 に表示される 1x サブ特集画像
今のところ、各記事を複数ではなく 1 つの画像に対応させたいと考えています。ただし、ユーザーは記事の画像をarticle_full
TEXT 列に投稿できます。
質問 #1.2 : 記事の画像をスキーマに組み込む方法がわかりません。このような 2 つのテーブルに依存するスキーマは一般的ですか?
article_image_links:
article_id article_image_id
1 1
記事の画像:
article_image_id article_image_url
1 media.site.com/articles/blah.jpg
データの要件:
私がSQLロジックを持っている方法から、ものが表示されるためにはいくつかのデータが必要です..
- there has to be at least one
main
type article - there has to be at least four
featured
type articles which are below the main one
Question #1.3: Should I bother creating special cases for if data is missing? For example, if there's no main featured article, should I select the latest featured, or should I make it a requirement that someone always specify a main article?
Question #1.4: In the admin, when a user goes to post, by default I'll have a dropdown which specifies the article type, normal
will be pre-selected and it will have the option for main
and featured
. So if a user at one point decides to change the article type, he/she can do that.
質問 #1.5 : 特集記事とメイン記事が最新の日付でしか機能しません。たとえば、ユーザーがなんらかの理由で古い記事をメインの記事として指定したい場合、カスタム ロジックを作成するか、記事の日付を最新のものよりも遅くなるように更新するように指示する必要がありますか?