Skip to content

Instantly share code, notes, and snippets.

@otang
Created April 19, 2014 05:10
Show Gist options
  • Save otang/11074749 to your computer and use it in GitHub Desktop.
Save otang/11074749 to your computer and use it in GitHub Desktop.
query = db.Auction.find
where:
id: req.params.auction
include: [
db.User
db.Region
db.Section
{ model: db.Image, as: 'thumbnail' }
{ model: db.Image, as: 'image' }
# Seller and seller's membership info
{
model: db.User
include:
model: db.Membership
foreignKey: 'user_id'
where:
group_id: req.group_id
}
]
query.success (auction) ->
if not auction then return res.json 404, "Not found"
# hacky: move membership from array to obj
if auction.user and auction.user.dataValues.membership and auction.user.dataValues.membership.length > 0
auction.user.dataValues.membership = auction.user.dataValues.membership[0]
res.json auction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment