I am going to migrate from rails 3 app, that used AR and arel to datamapper. I love chains of scopes like Person.where(…).where(…).somescope.paginate(…).order(…). how to migrate from this arel approach to datamapper.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Named scopes in DataMapper are simply class methods that you define on your model classes. Inside those class methods, you typically call
#allwith some conditions to get back aDataMapper::Collection. In order for your class methods to be chainable, you must make sure to return aDataMapper::Collection.For completeness’ sake, here are the installation instructions …
And the code to get you going (put this into test.rb for maximum reproducability)
See https://github.com/postmodern/dm-chunked_query for more information on the lowlevel approach to pagination (batch processing) that provides the
#chunksmethod used in this example.