I'm looking to sort records in one table, based on a date column in another 
table. For example, I have the following tables:

class BookReader
> include DataMapper::Resource
> has n, :checkouts
> has n, :books, :through => :checkouts
> property :id, Serial
> property :name, String
> property :city, String
> end
> class Book
> include DataMapper::Resource
> has n, :checkouts
> has n, :readers, :through => :checkouts
> property :id, Serial
> property :title, String
> property :author, String
> property :published, Date
> end
> class Checkout
> include DataMapper::Resource
> belongs_to :bookreader, :key => true
> belongs_to :book, :key => true
> property :created_at, DateTime
> property :updated_at, DateTime
> end


(This assumes each BookReader can only check out each Book once).
I can select all the Book objects belonging to a particular BookReader:

checkouts = BookReader.first.checkouts


Now, I want to sort these based on the :published date of the Book object. 
E.g.:

SELECT
> c.*, b.date
> FROM
> "checkouts" as c
> JOIN "books" as b on b.id = c.book_id
> WHERE
> c.bookreader_id = 1
> ORDER BY
> b.date DESC


Any way to do this directly through DM?

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/datamapper/-/SS4rSLbWrKQJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.

Reply via email to