ChromaticHQ / jsonmonger

23 stars 1 forks source link

Implement .toObject() method #6

Closed agarzola closed 6 years ago

agarzola commented 6 years ago

This PR implements a toObject() method that returns a vanilla Object following the schema for the object’s CustomModel.

Given the following CustomModel:

const Model = require('jsonmonger').Model;
const Author = new Model({
  name: 'attributes.full_name',
  books: 'relationships.authored_works',
  topics: 'relationships.authored_categories',
  influences: 'relationships.influences',
});

And given the following code:

const china = new Author({
  name: 'China Miéville',
});

console.log(china.toObject());

The console should read:

{
  name: "China Miéville"
}