私はデータベースの内部にテーブルを3つ持っています:interest
、subscription
、subscriber
です。スキーマは次のようになります。共通のテーブルを使って関係を正しく確立する
サブスクリプションテーブルには関心とサブスクライバの両方で一対多の関係を持っています。どのように動作させたいのですが、どのように動作させたいのか、そして実際にどのように動作しているのかは分かりませんが、これは次のようなものです:加入者は複数のインタレストを持つことができ、複数の加入者。これにより、加入者がどのような関心を持っており、どの関心が加入しているのかを見ることができます。次に、サブスクリプションは、1つのサブスクライバと1つの関心事にのみ関係します。
C:\xampp\htdocs\www\public_html\playground\subscribr>php list_subscriptions.php
[email protected]
--Magazine
--Newsletter
--Promotions
--Email
[email protected]
--Magazine
--Promotions
[email protected]
--Newsletter
--Email
-te[email protected]
--Magazine
--Promotions
--Email
[email protected]
--Magazine
[email protected]
--Newsletter
[email protected]
--Promotions
[email protected]
--Promotions
[email protected]
--Newsletter
I:私はもっとこのような結果を期待するとし
C:\xampp\htdocs\www\public_html\playground\subscribr>php list_subscriptions.php
[email protected]
--Magazine
[email protected]
--Newsletter
[email protected]
--Promotions
[email protected]
--Email
[email protected]
--Magazine
[email protected]
--Promotions
[email protected]
--Newsletter
[email protected]
--Email
[email protected]
--Magazine
[email protected]
--Promotions
[email protected]
--Email
[email protected]
--Magazine
[email protected]
--Newsletter
[email protected]
--Promotions
[email protected]
--Promotions
[email protected]
--Newsletter
:私はそれはそれはセットアップが、私はちょうどサブスクリプションテーブルを照会いくつかのテストでしたし、私はこのバックを持っているかだと思いますサブスクライバによってクエリを実行し、サブスクリプションテーブルを使用して関心を取得すると、この結果が得られます。私はORMを使用していますので、それを行うためのコードは次のようになります。
$subscriberRepo = $entityManager->getRepository('Subscribr\Entity\Subscriber');
$subscribers = $subscriberRepo->findAll();
foreach ($subscribers as $subscriber) {
echo sprintf("-%s\n", $subscriber->getEmail());
foreach ($subscriber->getInterests() as $interest) {
echo sprintf("--%s\n", $interest->getInterest()->getName());
}
}
だから私は、このスキーマを使用して、に加入している加入者のサブスクリプション、および利益を得ることができますが、その後、ポイントが調和してありますサブスクリプションテーブルの周り?それとも、私がやりたいことをするために、すべてのことを再加工する必要がありますか?サブスクライバテーブルからis_subscribed
を削除し、subscription_status
というサブスクリプションにカラムを追加するなど、サブスクリプションテーブルに余分なカラムを追加したい場合は、このソリューションが最もクリーンであると感じています。ただし、余分なフィールドを持つ結合テーブルのように感じることもほとんどありません。思考?
サブスクリプションテーブル*は、余分なフィールドを持つ結合テーブルです。だから何?これは、あなたが多くを表現する方法です:属性を持つ多くのバイナリ関係。さらに、あなたが「どのようにして加入者の購読と購読している興味を得ることができるか」*です。 ORMはそれを使用してgetInterests()を実装します。 – philipxy