Skip to content

Commit

Permalink
Add method to create entities in the store
Browse files Browse the repository at this point in the history
  • Loading branch information
danschultz committed Oct 22, 2011
1 parent 7f47bcc commit 1b0240b
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/mesh/model/store/Store.as
Expand Up @@ -64,6 +64,20 @@ package mesh.model.store
_commits.commit(entities);
}

/**
* Creates a new entity of the given type and given data.
*
* @param entityType The type of entity to create.
* @param data The data for the entity.
* @return A new entity.
*/
public function create(entityType:Class, data:Object):Entity
{
var key:Object = generateStoreKey();
_data.add(key, entityType, data, null);
return materialize(key);
}

/**
* Finds a single entity for a specific ID, or a list of entities matching a query.
*
Expand Down Expand Up @@ -151,10 +165,7 @@ package mesh.model.store
*/
public function insert(entityType:Class, data:Object, id:Object = null):Object
{
if (id == null) {
if (!data.hasOwnProperty("id")) {
throw new IllegalOperationError("Could not parse ID from data.");
}
if (id == null && data.hasOwnProperty("id")) {
id = data.id;
}

Expand Down

0 comments on commit 1b0240b

Please sign in to comment.