Open kettanaito opened 3 years ago
I was thinking about this the other day and thought it would be a great addition. In the Ruby world with factory_bot
they had a method called build
which allowed for creating non-persisted entities. https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#build-strategies
Motivation
Not all the modeled data are meant to be queryable. In certain cases, it's required to only describe the objects and have an API to seed them on demand. The required
primaryKey
at the moment prevents such usage of the library.API
I suggest adding a new public API designed for modeling objects in general, without querying capabilities. The
factory
could then reuse this new API internally, appending querying support.Specification
model
function accepts a model dictionary—an object of properties and their default value getters. Much like thefactory
does now, with the exception of the requiredprimaryKey
and relationships.model
function returns the following object:model.create()
returns a plain object with the described properties populated. There's no internal storage likeDatabase
for the factory.model.create()
behaves likedb.model.create()
at the moment.