Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to manipulate a has_many through in memory only?
    primarykey
    data
    text
    <p><strong>Platform:</strong> Rails 3</p> <p><strong>Requirement:</strong></p> <p>A form (<code>businesses#edit</code>) that allows a user to submit an update to a <code>Business</code> record (<code>businesses#update</code>.) When submitted <code>businesses#update</code> will not persist the changes to the database but will instead send an email with the new information for manual review.</p> <p><strong>How it's accomplished:</strong></p> <p>Load the <code>Business</code> model, update the properties in memory, pass it to an <code>ActionMailer</code>, finish without ever saving the model.</p> <p><strong>Problem:</strong></p> <p>The <code>Business</code> model has a <code>has_many :business_categories :through :business_categories_businesses</code> which is a <code>has_many :business_categories_businesses</code> and whenever I manipulate the <code>Business.business_categories</code> (<code>@business.business_categories = BusinessCategory.where(:id =&gt; params[:business][:business_categories])</code> for example.) the changes are immediately persisted to the database.</p> <p>I can not find any way of manipulating that collection in memory only so that it can be passed to an action mailer. In the short-term I'm going to hack it by not doing the assignment and simply pass the new collection of <code>BusinessCategories</code> to the ActionMailer to work out itself, but now this is just annoying me and I defer to the collective wisdom of the crowd:</p> <p>It is possible to manipulate has_many relations in memory only and if so how? Please save my sanity.</p> <p>Thank you in advance!</p>
    singulars
    1. This table or related slice is empty.
    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