Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model.toJSON with empty EagerRelation is ignored #33

Closed
ericclemmons opened this issue Jun 22, 2013 · 1 comment
Closed

Model.toJSON with empty EagerRelation is ignored #33

ericclemmons opened this issue Jun 22, 2013 · 1 comment

Comments

@ericclemmons
Copy link

var Blog = Bookshelf.Model.extend({
  tableName: 'blog'

  posts: function() {
    return this.belongsToMany(Post, 'blog_post');
});

var Post = Bookshelf.Model.extend({
  tableName: 'post'
});

If the blog has posts, you'll get back:

{
  id: 1,
  name: 'My blog',
  posts: [
    { ... },
    { ... }
  ]
}

If the blog does not have posts, you'll get back:

{
  id: 1,
  name: 'My blog'
}

I expect to at least see publishers: [] in the JSON.

tgriesser added a commit that referenced this issue Jun 25, 2013
* master:
  0.2.0
  some docs cleanups
  minor docs tweaks
  Pivot column typo, fixes #31
  Fix for #33, empty EagerRelation attachment, with tests.
  #30, allowing objects to be passed to query builder
  docs tweaks, blank target for some external links
  returning null for empty model fetch - #21
  better docs for attach, fixes #28
  fixing issue with exec plugin
@tgriesser
Copy link
Member

Thanks for pointing this out @ericclemmons - this should be fixed in the latest release, please let me know if you see any other issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants