new Collection( [collectionName])
The Collection class holding the date from the selected data source
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
collectionName |
String |
<optional> |
The name of the selected collection. Leave empty if you want an empty collection but with all methods |
Returns:
An array object with some extra methods added to it
- Type
- Collection
Extends
- Array
Methods
-
<static> decorate(collection)
-
Takes a collection object an appends all methods to it that are needed. This way we can work with a native array as a collection
Parameters:
Name Type Description collection
jsonOdm.Collection -
$hasMany(foreignKeyMapName, privateKeyField, childCollectionName [, alias])
-
// TODO needs a proper has many functionality that aromatically gathers the child elements Creates a has many relation to another collection
Parameters:
Name Type Argument Description foreignKeyMapName
Array | String The name of the field that holds an array of foreign keys
privateKeyField
int | String The private key of the foreign collection objects
childCollectionName
jsonOdm.Collection | String The child collection that belongs to the foreign keys
alias
String <optional>
The new field that will carry all connected data. This field must not exist before setting the relation
-
$hasOne(foreignKey, privateKeyField, childCollectionName, alias)
-
Creates a has many relation to another collection
Parameters:
Name Type Description foreignKey
String The name of the field holding a foreign key
privateKeyField
int | String The name of the private key field
childCollectionName
jsonOdm.Collection | String The child collection that belongs to the foreign keys
alias
String The new field that will carry the connected data.
Example
var customers = new jsonOdm.Collection("customers"); customers.$hasOne("id","customerGroupId","customerGroup","group"); console.log(customers[0]); // > {name:"Some Name",age:"25",...,customerGroupId:1,gourp:{id:1,name:"VIP"},...}
-
$query()
-
Creates a query object filled with the right collection data
Returns:
A new query object
- Type
- jsonOdm.Query