Skip to content

Latest commit

 

History

History
99 lines (66 loc) · 3.74 KB

EXTEND.rdoc

File metadata and controls

99 lines (66 loc) · 3.74 KB

For Tenacity to interact with a database client, the client needs to be extended to support the methods listed below. Beyond that, no additional configuration or code is necessary. Tenacity communicates with the client using only these methods, so as long as they have been implemented and are available on the model object, Tenacity will be able to manage the object’s relationships.

The Association Class

A few of the methods take an association as a parameter. This association is an instance of the Tenacity::Association class, which can be found at lib/tenacity/association.rb.

Class Methods

_t_id_type

The type to use when storing ids from instances of this class in a database. Usually String or Integer.

_t_find(id)

Find an object by its id, and return it. If the object cannot be found, return nil.

_t_find_bulk(ids=[])

Find many objects by the specified ids, and return them in an array. If no objects could be found, return an empty array. If only some of the objects could be found, then simply return those objects in the array.

_t_find_first_by_associate(property, id)

Find the first object by the specified property name, with the specified id, and return it. If no object could be found, return nil.

_t_find_all_by_associate(property, id)

Find all objects by the specified property name, with the specified id, and return them in an array. If no objects could be found, return an empty array.

_t_find_all_ids_by_associate(property, id)

Find all ids of rows/documents/etc by the specified property name, with the specified id, and return them in an array. If no data could be found, return an empty array.

_t_delete(ids, run_callbacks=true)

Delete all objects with the specified ids. If run_callbacks is true, the objects should be deleted in such a way that their delete callback methods are run. If false, the objects should be deleted in such a way that their delete callback meethods are not run. Return nothing.

_t_initialize_tenacity

Perform any database client specific initialization necessary to support Tenacity associations. This could include defining callbacks on the object required for all association types.

_t_initialize_has_many_association(association)

Perform any database client specific initialization necessary to support a has many association. This could include defining properties, or callback methods, on the object. This method must also call _t_cleanup_has_many_association(association) to cleanup the association when the after the object has been deleted.

_t_initialize_belongs_to_association(association)

Perform any database client specific initialization necessary to support a belongs to association. This could include defining properties, or callback methods, on the object. This method must also call _t_cleanup_belongs_to_association(association) to cleanup the association when the after the object has been deleted.

_t_initialize_has_one_association(association)

Perform any database client specific initialization necessary to support a has one association. This could include defining properties, or callback methods, on the object. This method must also call _t_cleanup_has_one_association(association) to cleanup the association when the after the object has been deleted.

Instance Methods

_t_reload

Reload the object from the database, overwriting the objects properties with the data fetched from the database. Returns the instance of the class (self).

_t_save_if_dirty

Save the object to the database only if the object has changed. This is solely for performance. If the client library does not support dirty tracking, this method can simply save the object. Returns the result of the save operation if the object was saved, or false if the object was not saved.