Data Mutation


    While this method creates a new object, there is no effect
    on the database until the save() method is called.

    This method can also be used to simulate loading a pre-existing object from the database, without actually querying the database:

    1. $post->title = 'New title';
    2. $success = $post->save();

    This will create an update query against the object with an ID matching $id. Also note that only the title field will be updated.

    The $data parameter is typically an array of key/value pairs that specify the new data with which the records will be updated. For SQL databases, this can optionally be an SQL fragment representing the clause of an UPDATE query. The $conditions parameter is an array of key/value pairs representing the scope of the records to be updated. The $options parameter specifies any database-specific options to use when performing the operation. The options parameter varies amongst the various types of data sources. More detail is available in the source code documentation for the update() methods of each data source type (Example: \lithium\data\source\Database.php).

    Deleting entities from your data source is accomplished using either the delete()
    entity method or the static remove() method.

    1. $post = Posts::first(); // Read the first post.

    To delete multiple records you first retrieve a set of entities
    then invoke the delete method on all of them. As the result
    of the find call here is actually a Collection any method
    called on the collection will be dispatched to each contained entity.

    As an alternative to quickly remove massive sets of entities remove() together with
    conditions can be used. The $conditions parameter is first and is an array of key/value
    pairs representing the scope of the records or documents to be deleted.

    1. // Delete all posts!!
    2. $success = Posts::remove();
    3. Posts::remove(['is_draft' => true]);

    Using the method with no $conditions
    parameter specified will delete all entities in your data source.