# First, last and each in differing orders

**URL:** <https://www.ruby-forum.com/t/first-last-and-each-in-differing-orders/98195>\
**Category:** Radiant CMS\
**Created:** [July 13, 2006, 12:40am UTC](https://www.ruby-forum.com/t/first-last-and-each-in-differing-orders/98195 "2006-07-13T00:40:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pond](https://www.ruby-forum.com/u/pond)\
**Post date:** [July 13, 2006, 12:40am UTC](https://www.ruby-forum.com/t/first-last-and-each-in-differing-orders/98195/1 "2006-07-13T00:40:12Z")

</div>

Is it a bug or intentional that \<r:children:first\> and \<r:children:last\>  
disagree with \<r:children:each\> about the first and last child by  
default in Radiant 0.50?

The :first and :last tags appear to return the same thing shown in the  
list of pages; that is, children sorted in alphabetical order by page  
title, irrespective of order of page creation. This isn’t what I  
expected. Meanwhile, \<r:children:each\> returns them in creation order,  
which _is_ more or less what I expected.

I presume the order can be modified in the :each case using the  
‘by=“attribute”’ feature, though I’m not entirely clear on what values  
are allowed for “attribute” [1]. It might be nice, though, if the  
default setting matched the behaviour of :first and :last. It’d also  
make more sense (to me at least) if :first really was the first child I  
created - can this be selected somehow, or is it hard-wired to sorting  
by title?

A cool future feature would allow “by” and “status” selectors on the  
:first and :last tags, assuming they’re not already supported.

[1] Indeed there are hints in the source code that \<r:title /\>,  
\<r:url /\> and so-on are part of a wider, general set of attributes  
but I don’t know where the list of these attributes is held yet, if  
indeed there is a list rather than some kind of run-time definition  
mechanism.

---

<div class="post-metadata">

**Author:** ![pond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pond](https://www.ruby-forum.com/u/pond)\
**Post date:** [July 13, 2006, 4:41pm UTC](https://www.ruby-forum.com/t/first-last-and-each-in-differing-orders/98195/2 "2006-07-13T16:41:36Z")

</div>

Andrew H. wrote:

> Is it a bug or intentional that \<r:children:first\> and \<r:children:last\>  
> disagree with \<r:children:each\> about the first and last child by  
> default in Radiant 0.50?

Ug. That would be a bug. 🙂 I’ve been meaning to rewrite these tags to  
simply call out to children each with `limit="1"`, but haven’t gotten  
around to it. Please submit a ticket and associate it with the next  
release.

> The :first and :last tags appear to return the same thing shown in the  
> list of pages; that is, children sorted in alphabetical order by page  
> title, irrespective of order of page creation. This isn’t what I  
> expected. Meanwhile, \<r:children:each\> returns them in creation order,  
> which _is_ more or less what I expected.

It’s actually by the published\_at field.

> I presume the order can be modified in the :each case using the  
> ‘by=“attribute”’ feature, though I’m not entirely clear on what values  
> are allowed for “attribute” [1].

You can use any attribute with is a column on the pages table. The  
\<r:children:each /\> tag just does a regular SQL query.

> It might be nice, though, if the  
> default setting matched the behaviour of :first and :last. It’d also  
> make more sense (to me at least) if :first really was the first child I  
> created - can this be selected somehow, or is it hard-wired to sorting  
> by title?

\<r:first /\> and \<r:last /\> should use \<r:children:each /\> as their  
implementation. As such they should also support the `by="attribute"`  
syntax.

> A cool future feature would allow “by” and “status” selectors on the  
> :first and :last tags, assuming they’re not already supported.

Yah, a status attribute would be good as well. Anyone have time to write  
a patch?

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)

---

<div class="post-metadata">

**Author:** ![pond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pond](https://www.ruby-forum.com/u/pond)\
**Post date:** [July 13, 2006, 6:28pm UTC](https://www.ruby-forum.com/t/first-last-and-each-in-differing-orders/98195/3 "2006-07-13T18:28:58Z")

</div>

John W. Long wrote:

> Please submit a ticket and associate it with the next release.

OK, done (I assume “0.6” is the next release…).

> > A cool future feature would allow “by” and “status” selectors on the  
> > :first and :last tags, assuming they’re not already supported.
> 
> Yah, a status attribute would be good as well. Anyone have time to write  
> a patch?

I might look into it once I’ve finished up on a couple of other things,  
of which more in other threads in due course.

---

<div class="post-metadata">

**Author:** ![pond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pond](https://www.ruby-forum.com/u/pond)\
**Post date:** [July 13, 2006, 7:02pm UTC](https://www.ruby-forum.com/t/first-last-and-each-in-differing-orders/98195/4 "2006-07-13T19:02:23Z")

</div>

Andrew H. wrote:

> John W. Long wrote:
> 
> > Please submit a ticket and associate it with the next release.
> 
> OK, done (I assume “0.6” is the next release…).

Yup. Though I think we may be due for a 0.5.1 release next week. It  
looks like I failed to include the .htaccess file in 0.5.0.

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)
