OpenRecord v2.8 Release Notes

Release Date: 2018-12-14 // almost 3 years ago
    • ➕ added record.update(data)
    • ➕ added record.isNewRecord

Previous changes from v2.5

  • It's now possible to create custom relations
    e.g.

    // models/User.jsthis.has('has\_posts\_written', { query: function(store, parentRecords){ const ids = parentRecords.map(r =\> r.id) const Post = store.Model('Post') // query all posts by user\_id, group by user\_id and count(distinct(id))return Post.totalCount().group('user\_id').where({user\_id: ids}) }, convert: function(parent, records){ if(!records) return false// records =\> [{user\_id: 1, count: 4}, {user\_id: 2, count: 1}]// == the result of the above query!const result = records.find(r =\> r.user\_id === parent.id) if(!result) return falsereturn result.count \> 0 } })
    

    A custom relation could return anything. In the example above it'll return a boolean value.

    Works with include() like any other relation:
    User.include('has_posts_written')