Let's say I have a Zookeeper (as in someone running a zoo and not the
Hadoop coordination software) entity that has an association of Animal
entities, which include Elephant, Monkey, and Giraffe subclasses. So I
have the following:

class Zookeeper
  include DataMapper::Resource
.
.
.
  has n, :animals
end



class Animal
  include DataMapper::Resource

  property :id, Serial
  property :type, Discriminator
  property :number_of_legs, Integer
  property :created_at, DateTime
  property :updated_at, DateTime
.
.
.
  belongs_to :zookeeper
end



class Elephant < Animal; end
class Monkey < Animal; end
class Giraffe < Animal; end


I would like to add a method to my Zookeeper class that can get the
last Elephant added to the collection as defined by the created_at
property. I feel like outside the class I could do something like

Elephant.last(:zookeeper_id => id)

But I would like the method to be part of the Zookeeper class. I have
studied the documentation, but I can't find a use case where the
parent of an association wants to locate one particular child in the
association.

Any insight is appreciated.

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
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