Note that there are some explanatory texts on larger screens.

plurals
  1. POSomething seems to be broken in my belongs_to, has_one relationship
    primarykey
    data
    text
    <p>I have a data model that looks like this:</p> <p>A <code>customer</code> has <code>subscription_id</code> and <code>setup_id</code> as parameters. In some cases, <code>customer</code> will only have one of the parameters. In other cases, it will have both. </p> <p>Currently, if I make a new customer through either the subscriptions flow or the setups flow, either <code>Subscription.last</code> or <code>Setup.last</code> will reflect the most recent customer that was created (with <code>customer_id</code> equalling the last customer created)</p> <p>However, I am having the problem of <code>Customer.setup_id</code> or <code>Custumer.subscription_id</code> being nil in all cases.</p> <p>Here's my code from both <code>subscription.rb</code> and <code>setup.rb</code>:</p> <pre><code>class Subscription &lt; ActiveRecord::Base attr_accessible :status, :customer_id belongs_to :customer end class Setup &lt; ActiveRecord::Base attr_accessible :status, :customer_id belongs_to :customer end </code></pre> <p>And in <code>customer.rb</code>:</p> <pre><code>class Customer &lt; ActiveRecord::Base attr_accessible :email, :name, :stripe_token, :subscription_id, :setup_id, :phone, :plan has_one :subscription has_one :setup end </code></pre> <p>I'm not sure what I'm doing incorrectly here but I'd love it if the three data models could talk to each other correctly.</p> <p><strong>Edit</strong>: Is it bad that both <code>setup</code> and <code>subscription</code> belong to <code>:user</code> rather than <code>:customer</code>?</p> <p><strong>Edit 2</strong>: Updated the code of setup.rb and subscriptions.rb to correctly reflect the data model currently. And <code>customer.rb</code> is still not recognizing the correct <code>setup_id</code> or <code>subscription_id</code></p>
    singulars
    1. This table or related slice is empty.
    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.
    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