shaoner / ziti

MySQL ORM for Node.js
http://ziti.ewdl.org/
MIT License
3 stars 0 forks source link

Allow to include association of association recursively #12

Closed shaoner closed 9 years ago

shaoner commented 9 years ago

It should be possible to:

  1. retrieve an association of an association
  2. define a condition on a reference:
var Photo = ziti.define('photo', {
    path: ziti.String,
    width: ziti.Int,
    height: ziti.Int,
    user: ziti.ForeignKey('User')
});

var User = ziti.define('User', {
    username: ziti.String,
    photos: [ Photo ]
});

User.at({ id: 42, photos: { width: 32, height: 32 } })
// SELECT * FROM `user` `User`
// LEFT JOIN `photo` `photos` ON `photos`.`user_id` = `User`.`id`
// AND `photos`.`width` = 32 AND `photos`.`height` = 32
shaoner commented 9 years ago

In this case, the relationship may not fit well, it should be possible to:

  1. retrieve an association of an association
  2. define a condition on a reference:
var Photo = ziti.define('photo', {
    path: ziti.String,
    width: ziti.Int,
    height: ziti.Int,
    user: ziti.ForeignKey('User')
});

var User = ziti.define('User', {
    username: ziti.String,
    photos: [ Photo ]
});

User.at({ id: 42, photos: { width: 32, height: 32 } })
// SELECT * FROM `user` `User`
// LEFT JOIN `photo` `photos` ON `photos`.`user_id` = `User`.`id`
// AND `photos`.`width` = 32 AND `photos`.`height` = 32