Skip to content

Instantly share code, notes, and snippets.

@lacco
Created December 16, 2009 09:19
Show Gist options
  • Save lacco/257704 to your computer and use it in GitHub Desktop.
Save lacco/257704 to your computer and use it in GitHub Desktop.
require 'factory_girl'
Dir["spec/factories/*"].each{|f| require f}
Factory.create :product
#=> new product with id=12
Product.first.update_versioned(:charge_interval => 'daily')
#=> new product with id=13
Product.all(:conditions => "id IN (select id from abstract_products group by name, edition having max(version))")
#=> Finds 12 instead of 13
Product.all(:conditions => 'version = (SELECT MAX(version) FROM abstract_products AS inner_abstract_products WHERE inner_abstract_products.name = abstract_products.name)')
#=> Finds 13 correctly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment