| clone | -> | couch_object_origianl_clone |
|
When saved, clones and dupes are stored as separate documents from the
object it originated from
Returns:
|
||
| created_at | [R] | Accessors for instance variables specific to the persistable CouchObject |
| id | [R] | Accessors for instance variables specific to the persistable CouchObject |
| revision | [R] | Accessors for instance variables specific to the persistable CouchObject |
| updated_at | [R] | Accessors for instance variables specific to the persistable CouchObject |
Adds timestamps to the class.
Example:
class Vacation
include CouchObject::Persistable
add_timestamp_for :on_create, :on_update
end
my_vacation = Vacation.new
my_vacation.save(db_address)
my_vacation.created_at => Somedate
my_vacation.updated_at => Somedate
Defines a belongs_to relation which then again needs a corresponding has_many relation in the class the relation is made with (see the documentation of has_many above)
Takes:
Example:
belongs_to :fruit_basket, :as => :fruits
Requires a has_many relation from the other class that looks
something like this:
has_many :fruits
Raises:
or the :as parameter is left blank.
Smart save can also be used on a per-case basis if it is sometimes needed and sometimes not.
Example:
user_without_smart_save_1 = User.get("foo") User.smart_save user_with_smart_save = User.get("bar") User.deactivate_smart_save user_without_smart_save_2 = User.get("bong")
Defines a has_many relation which then again needs a corresponding belongs_to relation in the classes the relation is made with (see the documentation of belongs_to below)
Takes:
Example:
has_many :fruits
Requires a belongs_to relation from the other part. F.ex:
belongs_to: :fruit_basket, :as => :fruits
Raises:
Location methods are added both as instance methods and as class level methods. The class level methods are needed when loading new objects from the database and the instance methods are used throughout the class
Smart save (defaults to false), if activated, keeps a snapshot of the objects initial state and evaluates if the class needs to be saved to the database by comparing it to the snapshot when a save is requested.
Please notice: Only activate this feature in cases where it is needed. It might slow down the performance of your app if you activate it for classes that you need many instances of and that you won‘t call the save method on after having loaded them from the database. Please also bare in mind that the class instance will store an extra copy of its contents which will lead to quite a big memory overhead for classes that store a lot of data!
<= and >= Uses the results from the methods ==, < and > to determine the result
Takes:
Raises:
Returns:
Equality is checked for using the following rules:
Takes:
Returns:
Goal: The goal is to return true for the object which has the newest representation in the database.
Requires:
Returns:
Takes:
Raises:
Returns:
This method is called from the method that assigns a belongs_to relation to inform the master object of the relation (has_many relations)
Stores the initial value of the instance to a variable for later reference by the +unsaved_changes?+ method
Returns the name of the relation in itself matching one of the relations in the other object
Example:
other_object has defined the relationships:
belongs_to :house, :as => :houses
belongs_to :humanity
self has the relation
has_many :houses
:houses is returned
Any instance should be able to delete itself
Takes:
Returns:
Note:
Raises:
If you need to access the belongs_to variable without loading the relation if it hasn‘t already been loaded, you can call the instance method do_not_load_belongs_to_relations. To reactivate loading so the relation is loaded the next time it is needed, call the instance method do_load_belongs_to_relations.
This method is called from the method that assigns a belongs_to relation to inform the previous master object that the relation ship has ended (has_one relations)
Breaks relations if existing
Takes:
Returns:
Saves the object to the db_uri supplied, or if not set, to the location the object has previously been saved to.
Takes:
Raises:
Returns:
Sub methods might raise:
This method is called from the method that assigns a belongs_to relation to inform the master object of the relation (has_one relations)
Sets the location variable manually
Takes:
serializes this object into JSON
Returns:
Example {"class":"Bike","attributes":{"wheels":2}}
Classes WITH smart_save activated: Any instance should be able to know if it has unsaved changes or not. When an instance is loaded from the DB it creates a snapshot of what its variables contain. Based on a comparison between the snapshot and the contents of the instance this method returns true or false.
Classes WITHOUT smart_save activated: Will always return true regardless of what state it is in
A new object will always return true
Returns:
Saves the class as a new document in the database
Returns:
Raises:
Loads the belongs_to relation if the class has a previously save relation
Updates a document in the database based on the id and revision
Returns:
Raises: