Nested associations

18 views
Skip to first unread message

Daniel Dickison

unread,
May 16, 2010, 10:58:36 AM5/16/10
to etsy-...@googlegroups.com
I'm trying to figure out the best way to get nested associations from a query without having to make multiple API calls. My specific use case is to fetch all of a user's favorite listings, along with thumbnail images and seller names. So, using a hypothetical shell-expansion-like syntax, I need something like:
/users/:user_id/favorites/listings?includes=Listing/{Images,Shop}

Ideally I want to do this query when fetching a user's other info, and with field filtering, so I want:
/users/:user_id?includes=FavoriteListings/Listing/{Images(url_50x50),Shop(login_name)}

After some trial and error, I found that I can include the same association multiple times in an includes parameter, so I can achieve this by doing:
/users/:user_id?FavoriteListings/Listing/Images(url_50x50),FavoriteListings/Listing(listing_id)/User(login_name)

This returns redundant data (each FavoriteListing shows up twice, once for the Images "subquery" and once for the User "subquery"). It's possible to minimize the duplicity by filtering unneeded fields from the second subquery, but it still seems a bit hacky.

Can I count on this method to keep working? Or is there (or will there be) a better way to do this type of thing?

Daniel

Justin Kerr Sheckler

unread,
May 17, 2010, 10:39:10 AM5/17/10
to etsy-...@googlegroups.com
The duplicate entries appears to be a regression since we introduced
fieldname filtering--we'll take a look.

Also, great idea with the curly brace syntax (I'll admit that hadn't
occured to me.) I'll see if there's a way to make that work.

JKS
--
Justin Kerr Sheckler
Developer API Lead
Etsy.com
jus...@etsy.com
Reply all
Reply to author
Forward
0 new messages