how to order by sub-entity attribute?

95 views
Skip to first unread message

jon...@gmail.com

unread,
Mar 11, 2011, 11:32:10 AM3/11/11
to persistence.js
I've got the following entities:

var Hotel = persistence.define('Hotel', {
name: "TEXT",
numUnits: "INT",
favorite: "BOOL"
});

var Country = persistence.define('Country', {
name: "TEXT"
});

Hotel.hasOne('country', Country);

I'm trying to order a queried set of hotels by their country name, but
I can't find syntax that works:

collection.order("hotel.country.name", false).list(null, function
(results) {...}); //produces ORDER BY `Hotel_hotel.country.name` DESC

collection.order("country.name", false).list(null, function (results)
{...}); //produces ORDER BY `Property_country.name` DESC

collection.order("country_name", false).list(null, function (results)
{...}); //ORDER BY `Hotel_country_name` DESC

I see that the country.name property gets aliased in the query as
"country_name", but when I try to use that, 'Hotel_' gets prepended in
the order by clause. Is there another route I'm missing? Thanks!

jon...@gmail.com

unread,
Mar 11, 2011, 11:33:14 AM3/11/11
to persistence.js
Typo fix...

On Mar 11, 11:32 am, "jon...@gmail.com" <jon...@gmail.com> wrote:
> I've got the following entities:
>
> var Hotel = persistence.define('Hotel', {
>     name: "TEXT",
>     numUnits: "INT",
>     favorite: "BOOL"
>
> });
>
> var Country = persistence.define('Country', {
>     name: "TEXT"
>
> });
>
> Hotel.hasOne('country', Country);
>
> I'm trying to order a queried set of hotels by their country name, but
> I can't find syntax that works:
>
> collection.order("hotel.country.name", false).list(null, function
> (results) {...}); //produces ORDER BY `Hotel_hotel.country.name` DESC
>
> collection.order("country.name", false).list(null, function (results)
> {...}); //produces ORDER BY `Hotel_country.name`  DESC

jon...@gmail.com

unread,
Mar 14, 2011, 2:54:21 PM3/14/11
to persistence.js
Might have shot myself in the foot with this post-- my typo fix was
for the post itself, not the solution to the issue I'm trying to post
about. Zef or anybody, do you have a suggestion for me for how to
order by a property of an entity type that's not the main entity I'm
querying on?

Thanks...

Zef Hemel

unread,
Mar 14, 2011, 3:22:15 PM3/14/11
to persis...@googlegroups.com
Sorry, forgot to answer before.

persistence.js does not currently support filtering or ordering across
tables, so currently you can simply not do this. If you're interested
in adding this feature you're very welcome to help!

Best,

Zef

--
Zef Hemel
http://zef.me
http://twitter.com/zef

Reply all
Reply to author
Forward
0 new messages