Chris,

What validations do you have on the Campaign model? I suspect you're running into something like validates_uniqueness_of, which uses a select to determine whether the attribute is unique or not.

- Jamis

Chris Abad wrote:
Full code:
http://pastie.caboo.se/7856

Relevant code:

@campaign = *Campaign*.find(:first, :conditions => ['id=? AND user_id=?', params[:id], *self*.current_user.id])
------------------------------
Campaign Load (0.085124) SELECT * FROM campaigns WHERE (id='34' AND user_id=9) LIMIT 1

@campaign.update_attributes(:design_id => params[:design_id])
-----------------------------
Campaign Load (0.079262) SELECT * FROM campaigns WHERE (campaigns.subdomain = 'YorkCounty' AND campaigns.domain = '1landing.com' AND campaigns.id <> 34) LIMIT 1

So here's my question... why does update_attributes run a new SELECT query, and why is it using all those unnecessary conditions? I was even running into an issue where sometimes the SELECT query wouldn't find what it was looking for and therefore the update never happened (which is why I started digging in the first place. I then tried this:

@campaign.update_attribute(:design_id,params[:design_id])

This seems to work just fine. It doesn't run the unnecessary select query and goes straight to the UPDATE query using the proper id. I'm not sure what the difference is since looking at the source, update_attributes and update_attribute appear to be almost identical. Can anyone shed some light on this?

Thanks.


------------------------------------------------------------------------

_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core

_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core

Reply via email to