Skip to content
David Souther edited this page Dec 24, 2012 · 1 revision

Constructor

Entities do not have constructors. Entities should be created using a Runtime's build factory method.

Methods

Entity methods are created by the runtime when an entity type is read from a context.

id(full=false) -> ID

Return the ID of the object, independent of whichever property actually stores it.

  • full When true, prefix the ID with the entity's type.

returns The ID of the entity in the runtime's native format.


_type(full=false) -> String

Returns a string of the canonical entity type.

  • full When true, return the type including context URI prefix.

returns The entity type.

_status() -> MODIFIED|NEW|PERSISTED

Determine the entity's persistence state. MODIFIED indicates the entity has been persisted to another JEFRi Runtime, but has more recent data that hasn't been stored. PERSISTED indicates all values in the local copy of the entity have been persisted to at least one other runtime. NEW indicates that this entity has never been sent to a remote runtime.

returns A value from the enumeration of entity states. See implementation's documentation for return type of the enumeration.


_definition() -> Definition

Get a representation of the entity's context definition.

returns A bare object with the definition of the entity's type.


_persist(transaction) -> Promise

Register an entity with a persistence transaction.

  • transaction The transaction to attach to. If empty, starts a new transaction against the default store and executes it.

returns A promise representing the completion of the persist transaction.


_encode() -> bare object

Return a stripped representation of the object that is suitable to add to a data structure to be stringified.

returns A bare object with only the serializable parts of the entity.


'navprop'(args) -> value|Entity|[Entity...]

Overloaded and combined getter and setter. If given no arguments, acts as 'navprop'.get(). If given arguments, acts as either 'navprop'.set(args) or 'navprop'.add(args), depending on the type of the relationship.

  • args Either empty, an entity, or an array of entities.

returns Either this entity, the single related entity, or an array of related entities.


'navprop'.get() -> Entity|[Entity...]

Follow a navigation property or look up a property. If key refers to a property, return its current value. If the relationship is an is_a, return an instance of the to type. If the relationship is a has_a, return a (possibly new) instance of the to type. If the relationship is a has_many, return a (possibly empty) array of entities of the to type. If there is a property and a relationship with the same name, look up the relationship.

returns The property value, the navigated entity, or an array of the navigated entity.


'navprop'.set(value) -> this

Set the property or has_a navigation property. Correctly updates each entities' navigation property values. If there is a property and a relationship with the same name, look up the relationship.

  • to_entity New entity for a property or has_a relationship.

returns A reference to this entity.


'navprop'.add(to_entity) -> this

Add to the has_many array.

  • to_entity New entity to add to the has_many list.

returns A reference to this entity.


'navprop'.remove(to_entity) -> this

Remove the entity from the relationship. If the relationship is has_many, to_entity will be removed from the array. If the relationship is has_a, relationship.to_property and the relationship will be nulled.

Events

persisting this, transaction Triggered during the transaction lifecycle when a transaction begins to persist to a remote runtime, but before the data has been sent.

  • this A reference to the entity itself.
  • transaction The transaction that is persisting this entity.

persisted this Triggered during the transaction lifecycle, after it has been confirmed that the entity was persisted in the remote runtime.

  • this A reference to the entity itself, with updated field values from the persist transaction.

gotten this Triggered after an entity has been returned and interned from a get transaction

  • this A reference to the entity, with properties updated from the values returned in the transaction.

modified this, property, value Triggered when a property on this entity is updated.

  • this The entity the modification happened in.
  • property The property name that was changed.
  • value The new value of the property.
Clone this wiki locally