[DataMapper] Re: Order Across Associations: Is It Possible?

2013-02-18 Thread abuwabu
Thanks Neil, much obliged


On Monday, 18 February 2013 04:24:28 UTC, Neil C wrote:

 The best I could do is a hack using collect. Something like 

 parent.children.collect {|child| child.name}

 Whether this is sound depends on whether you have the memory for it. 
 Otherwise, you probably have to write a native SQL query if you want to put 
 the burden on the DB engine. Or wait for DM 2.0.

 Thanks.


 On Sunday, February 17, 2013 6:06:50 PM UTC-5, abu...@gmail.com wrote:

 *bump*

 Did you find a solution to this Neil?

 I found an old thread: 
 https://groups.google.com/forum/?fromgroups=#!topic/datamapper/BChZ83gDSqQ

 It is 3 years old now though. Is there a way to achieve this?

 Cheers all
 Adam

 On Saturday, 12 January 2013 01:15:21 UTC, Neil C wrote:

 I made a mistake in my earlier question since I just typed it out. 
 Obviously parent.children.name wouldn't work because Collection doesn't 
 have a name property.

 So the better question is: Given the class definitions above, how would 
 I get the names of the kids from oldest to youngest?

 Thanks and sorry for the confusion.


 On Friday, January 11, 2013 7:22:00 PM UTC-5, Neil C wrote:

 Imagine Parent and Child classes as you might expect:

 class Parent
   include DataMapper::Resource

   property :id, Serial
   property :name, String, :required = true

   has n, :children, :order = :age.desc   #Note default order by age 
 descending (i.e. oldest to youngest)
 end

 class Child
   include DataMapper::Resource

   property :id, Serial
   property :name, String, :required = true
   property :age, String, :required = true

   belongs_to :parent
 end

 I now want the names of the kids from oldest to youngest so I do this

 parent.children.name

 The problem is that the order by age descending isn't being applied; in 
 fact, it is ignored. I am getting the names sorted by id.

 Is it even possible to maintain order across associations? If so, how?

 Thanks.




-- 
You received this message because you are subscribed to the Google Groups 
DataMapper group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to datamapper+unsubscr...@googlegroups.com.
To post to this group, send email to datamapper@googlegroups.com.
Visit this group at http://groups.google.com/group/datamapper?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [DataMapper] Re: Order Across Associations: Is It Possible?

2013-02-18 Thread Martin Gamsjaeger
guys, maybe this helps:
http://rhnh.net/2010/12/01/ordering-by-a-field-in-a-join-model-with-datamapper

cheers
snusnu


On Mon, Feb 18, 2013 at 2:53 PM, abuw...@gmail.com wrote:

 Thanks Neil, much obliged


 On Monday, 18 February 2013 04:24:28 UTC, Neil C wrote:

 The best I could do is a hack using collect. Something like

 parent.children.collect {|child| child.name}

 Whether this is sound depends on whether you have the memory for it.
 Otherwise, you probably have to write a native SQL query if you want to put
 the burden on the DB engine. Or wait for DM 2.0.

 Thanks.


 On Sunday, February 17, 2013 6:06:50 PM UTC-5, abu...@gmail.com wrote:

 *bump*

 Did you find a solution to this Neil?

 I found an old thread: https://groups.google.**
 com/forum/?fromgroups=#!topic/**datamapper/BChZ83gDSqQhttps://groups.google.com/forum/?fromgroups=#!topic/datamapper/BChZ83gDSqQ

 It is 3 years old now though. Is there a way to achieve this?

 Cheers all
 Adam

 On Saturday, 12 January 2013 01:15:21 UTC, Neil C wrote:

 I made a mistake in my earlier question since I just typed it out.
 Obviously parent.children.name** wouldn't work because Collection
 doesn't have a name property.

 So the better question is: Given the class definitions above, how would
 I get the names of the kids from oldest to youngest?

 Thanks and sorry for the confusion.


 On Friday, January 11, 2013 7:22:00 PM UTC-5, Neil C wrote:

 Imagine Parent and Child classes as you might expect:

 class Parent
   include DataMapper::Resource

   property :id, Serial
   property :name, String, :required = true

   has n, :children, :order = :age.desc   #Note default order by age
 descending (i.e. oldest to youngest)
 end

 class Child
   include DataMapper::Resource

   property :id, Serial
   property :name, String, :required = true
   property :age, String, :required = true

   belongs_to :parent
 end

 I now want the names of the kids from oldest to youngest so I do this

 parent.children.name

 The problem is that the order by age descending isn't being applied;
 in fact, it is ignored. I am getting the names sorted by id.

 Is it even possible to maintain order across associations? If so, how?

 Thanks.


  --
 You received this message because you are subscribed to the Google Groups
 DataMapper group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to datamapper+unsubscr...@googlegroups.com.
 To post to this group, send email to datamapper@googlegroups.com.
 Visit this group at http://groups.google.com/group/datamapper?hl=en.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
You received this message because you are subscribed to the Google Groups 
DataMapper group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to datamapper+unsubscr...@googlegroups.com.
To post to this group, send email to datamapper@googlegroups.com.
Visit this group at http://groups.google.com/group/datamapper?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




[DataMapper] Re: Order Across Associations: Is It Possible?

2013-02-17 Thread abuwabu
*bump*

Did you find a solution to this Neil?

I found an old 
thread: 
https://groups.google.com/forum/?fromgroups=#!topic/datamapper/BChZ83gDSqQ

It is 3 years old now though. Is there a way to achieve this?

Cheers all
Adam

On Saturday, 12 January 2013 01:15:21 UTC, Neil C wrote:

 I made a mistake in my earlier question since I just typed it out. 
 Obviously parent.children.name wouldn't work because Collection doesn't 
 have a name property.

 So the better question is: Given the class definitions above, how would I 
 get the names of the kids from oldest to youngest?

 Thanks and sorry for the confusion.


 On Friday, January 11, 2013 7:22:00 PM UTC-5, Neil C wrote:

 Imagine Parent and Child classes as you might expect:

 class Parent
   include DataMapper::Resource

   property :id, Serial
   property :name, String, :required = true

   has n, :children, :order = :age.desc   #Note default order by age 
 descending (i.e. oldest to youngest)
 end

 class Child
   include DataMapper::Resource

   property :id, Serial
   property :name, String, :required = true
   property :age, String, :required = true

   belongs_to :parent
 end

 I now want the names of the kids from oldest to youngest so I do this

 parent.children.name

 The problem is that the order by age descending isn't being applied; in 
 fact, it is ignored. I am getting the names sorted by id.

 Is it even possible to maintain order across associations? If so, how?

 Thanks.




-- 
You received this message because you are subscribed to the Google Groups 
DataMapper group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to datamapper+unsubscr...@googlegroups.com.
To post to this group, send email to datamapper@googlegroups.com.
Visit this group at http://groups.google.com/group/datamapper?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




[DataMapper] Re: Order Across Associations: Is It Possible?

2013-02-17 Thread Neil C
The best I could do is a hack using collect. Something like 

parent.children.collect {|child| child.name}

Whether this is sound depends on whether you have the memory for it. 
Otherwise, you probably have to write a native SQL query if you want to put 
the burden on the DB engine. Or wait for DM 2.0.

Thanks.


On Sunday, February 17, 2013 6:06:50 PM UTC-5, abu...@gmail.com wrote:

 *bump*

 Did you find a solution to this Neil?

 I found an old thread: 
 https://groups.google.com/forum/?fromgroups=#!topic/datamapper/BChZ83gDSqQ

 It is 3 years old now though. Is there a way to achieve this?

 Cheers all
 Adam

 On Saturday, 12 January 2013 01:15:21 UTC, Neil C wrote:

 I made a mistake in my earlier question since I just typed it out. 
 Obviously parent.children.name wouldn't work because Collection doesn't 
 have a name property.

 So the better question is: Given the class definitions above, how would I 
 get the names of the kids from oldest to youngest?

 Thanks and sorry for the confusion.


 On Friday, January 11, 2013 7:22:00 PM UTC-5, Neil C wrote:

 Imagine Parent and Child classes as you might expect:

 class Parent
   include DataMapper::Resource

   property :id, Serial
   property :name, String, :required = true

   has n, :children, :order = :age.desc   #Note default order by age 
 descending (i.e. oldest to youngest)
 end

 class Child
   include DataMapper::Resource

   property :id, Serial
   property :name, String, :required = true
   property :age, String, :required = true

   belongs_to :parent
 end

 I now want the names of the kids from oldest to youngest so I do this

 parent.children.name

 The problem is that the order by age descending isn't being applied; in 
 fact, it is ignored. I am getting the names sorted by id.

 Is it even possible to maintain order across associations? If so, how?

 Thanks.




-- 
You received this message because you are subscribed to the Google Groups 
DataMapper group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to datamapper+unsubscr...@googlegroups.com.
To post to this group, send email to datamapper@googlegroups.com.
Visit this group at http://groups.google.com/group/datamapper?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




[DataMapper] Re: Order Across Associations: Is It Possible?

2013-01-11 Thread Neil C
I made a mistake in my earlier question since I just typed it out. 
Obviously parent.children.name wouldn't work because Collection doesn't 
have a name property.

So the better question is: Given the class definitions above, how would I 
get the names of the kids from oldest to youngest?

Thanks and sorry for the confusion.


On Friday, January 11, 2013 7:22:00 PM UTC-5, Neil C wrote:

 Imagine Parent and Child classes as you might expect:

 class Parent
   include DataMapper::Resource

   property :id, Serial
   property :name, String, :required = true

   has n, :children, :order = :age.desc   #Note default order by age 
 descending (i.e. oldest to youngest)
 end

 class Child
   include DataMapper::Resource

   property :id, Serial
   property :name, String, :required = true
   property :age, String, :required = true

   belongs_to :parent
 end

 I now want the names of the kids from oldest to youngest so I do this

 parent.children.name

 The problem is that the order by age descending isn't being applied; in 
 fact, it is ignored. I am getting the names sorted by id.

 Is it even possible to maintain order across associations? If so, how?

 Thanks.




-- 
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/-/RkESaXL3M40J.
To post to this group, send email to datamapper@googlegroups.com.
To unsubscribe from this group, send email to 
datamapper+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.