Skip to content

Instantly share code, notes, and snippets.

@davelnewton
Created April 25, 2012 17:06
Show Gist options
  • Save davelnewton/2491340 to your computer and use it in GitHub Desktop.
Save davelnewton/2491340 to your computer and use it in GitHub Desktop.
DataMapper create-/query-by-hash equivalence
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">]
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