jgaskins / perpetuity

Persistence gem for Ruby objects using the Data Mapper pattern
http://jgaskins.org/blog/2012/04/20/data-mapper-vs-active-record/
MIT License
250 stars 14 forks source link

Select DSL breaks when using ivars #19

Closed jgaskins closed 11 years ago

jgaskins commented 11 years ago

The following query doesn't do as you might think:

Perpetuity[User].select { email == @email }

This is because the DSL evaluates in the context of a Perpetuity::MongoDB::Query to make use of method_missing to find out which attributes are being used. We might be able to do a different type of select that resembles Enumerable more closely (as in mapper.select { |user| user.email == @email }) by calling the block with a Query as an argument rather than using instance_exec on the block.

Will investigate.

jgaskins commented 11 years ago

Fixed in 120b72731de86f9a1c9011ab887c642942665d17. I really didn't expect that to be such an easy fix.