Created
April 25, 2012 17:06
-
-
Save davelnewton/2491340 to your computer and use it in GitHub Desktop.
DataMapper create-/query-by-hash equivalence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
customer = { | |
:name => 'Dan Kubb', | |
:orders => [ | |
{ | |
:reference => 'TEST1234', | |
:order_lines => [ | |
{ | |
:item => { | |
:sku => 'BLUEWIDGET1', | |
:unit_price => 1.00, | |
}, | |
}, | |
], | |
}, | |
] | |
} | |
# Create the Customer with the nested options hash | |
Customer.create(customer) | |
# => [#<Customer @id=1 @name="Dan Kubb">] | |
# The same options to create can also be used to query for the same object | |
p Customer.all(customer) | |
# => [#<Customer @id=1 @name="Dan Kubb">] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 Customer.all(Customer.orders.order_lines.item.sku.like => "%BLUE%") | |
2 # => [#<Customer @id=1 @name="Dan Kubb">] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment