Skip to content

Instantly share code, notes, and snippets.

@piyushranjan
Created May 4, 2010 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piyushranjan/389384 to your computer and use it in GitHub Desktop.
Save piyushranjan/389384 to your computer and use it in GitHub Desktop.
require "dm-core"
DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, 'mysql://test@localhost/dm_test')
class Amount
include DataMapper::Resource
property :id, Serial
property :amount_1, Integer
property :amount_2, Integer
end
DataMapper.auto_migrate!
Amount.create(:amount_1 => 10, :amount_2 => 20)
Amount.create(:amount_1 => 20, :amount_2 => 20)
p Amount.all(:conditions => ['amount1 = amount2'])
~ (0.000003) CREATE TABLE `amounts` (`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `amount_1` INTEGER, `amount_2` INTEGER, PRIMARY KEY(`id`)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
~ (0.000004) INSERT INTO `amounts` (`amount_1`, `amount_2`) VALUES (10, 20)
~ (0.000004) INSERT INTO `amounts` (`amount_1`, `amount_2`) VALUES (20, 20)
~ (0.000004) SELECT `id`, `amount_1`, `amount_2` FROM `amounts` ORDER BY `id`
[#<Amount @id=1 @amount_1=10 @amount_2=20>, #<Amount @id=2 @amount_1=20 @amount_2=20>]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment