Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Avoid <code>default_scope</code> if possible</strong>. I think you should really re-ask yourself why you need a <code>default_scope</code>. Countering a <code>default_scope</code> is often messier than it's worth and it should only be used in rare cases. Also, using <code>default_scope</code> isn't very revealing when ticket associations are accessed outside the Ticket model (e.g. <em>"I called <code>account.tickets</code>. Why aren't my tickets there?"</em>). This is part of the reason why <code>with_exclusive_scope</code> is protected. You should taste some <a href="http://www.loudthinking.com/arc/2006_10.html" rel="noreferrer">syntactic vinegar</a> when you need to use it.</p> <p>As an alternative, use a gem/plugin like <a href="http://github.com/thoughtbot/pacecar" rel="noreferrer">pacecar</a> that automatically adds useful named_scopes to your models giving you more revealing code everywhere. For Example:</p> <pre><code>class Ticket &lt; ActiveRecord::Base include Pacecar belongs_to :user end user.tickets.ends_at_in_future # returns all future tickets for the user user.tickets # returns all tickets for the user </code></pre> <p>You can also decorate your User model to make the above code cleaner:</p> <pre><code>Class User &lt; ActiveRecord::Base has_many :tickets def future_tickets tickets.ends_at_in_future end end user.future_tickets # returns all future tickets for the user user.tickets # returns all tickets for the user </code></pre> <p>Side Note: Also, consider using a more idiomatic datetime column name like <code>ends_at</code> instead of <code>end_date</code>.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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