Uniqueness constraints in vae() and <v:collection> - May 21, 2010

Let's say you had a catalog of albums stored in a collection.  Each album was released during a specific year.  If you wanted to display to display all the years where your record label created albums, you'd probably do something like:

<v:collection path="/albums" order="DESC(year)">
 <v:text path="year" />
</v:collection>

But this might actually produce something like this:

2010
2010
2010
2009
2009
2008
2008
(etc.)

Eww, look at all those repeats.  That's not what you wanted.

Now Vae provides a way to select only the first record for each year, so you can display your list as intended.  Simply add unique="year" to the <v:collection> tag.  Or, if you're using our PHP API, just add 'unique' => 'year' to your array of options that you pass into vae().

So something like this:

<v:collection path="/albums" order="DESC(year)" unique="year">
 <v:text path="year" />
</v:collection>

Would produce something like this:

2010
2009
2008
(etc.)

Note -- you can look for unique sets of structures by specifying their names separated by commas.  For example unique="year,month".

This was non-trivial for us to implement, so I hope that you are able to take this and go make something cool with it!