Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat's the best way to model these database associations?
    primarykey
    data
    text
    <p>So I have the following models:</p> <ul> <li>User</li> <li>Business</li> <li>Coupons</li> <li>Deals</li> <li>Redeemable</li> <li>owner</li> </ul> <p>I am using the owner model to associate various other models such as business coupons deals and redeemable to the user model.</p> <p>The redeemable model is used because I want to generate a unique code for each user that uses a coupon/deal in order to limit one per user as well as the amount in total.</p> <p>I suppose maybe I don't need two models for coupon and deal and I just need one because a deal is more like a special type of coupon.</p> <p>So heres the models after a revision:</p> <pre><code>Business has_many :owners, :as =&gt; :ownable, :dependent =&gt; :destroy has_many :coupons, :dependent =&gt; :destroy Coupon belongs_to :business has_many :redeems # also has a special column for denoting weather it's a # normal coupon or a daily deal kind of coupon Redeem belongs_to :coupon has_one :owner, :as =&gt; :ownable, :dependent =&gt; :destroy Owner belongs_to :user belongs_to :ownable, :polymorphic =&gt; true </code></pre> <p>and for the user model I am just totally lost but here's what I want in pseudo code edit just for all those who may have same problem here's how i set up the user model</p> <pre><code>User has_many :owners has_many :businesses, :through =&gt; :owners, :source =&gt; business, :source_type =&gt; 'Business' has_many :redeems, :through =&gt; :owners, :source=&gt; :redeem, :source_type =&gt; 'Redeem' has_many :coupons, :through =&gt; :redeems, :source =&gt; :coupon, :source_type =&gt; 'Coupon' </code></pre> <p>I just don't understand how to associate the coupons with the User model because I did a polymorphic association for owning things.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload