2017 © Pedro Peláez
 

kohana-module jam-freezable

Freeze dynamically computed values in the database using Jam

image

openbuildings/jam-freezable

Freeze dynamically computed values in the database using Jam

  • Wednesday, April 9, 2014
  • by hkdobrev
  • Repository
  • 14 Watchers
  • 1 Stars
  • 3,014 Installations
  • PHP
  • 0 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Freezable Behavior

Build Status Scrutinizer Quality Score Code Coverage Latest Stable Version, (*1)

Freezable is a Jam ORM behavior for freezing dynamically computed values in the database., (*2)


Often one would have a method in the model which computes and returns a value. It could be a price, time or anything else. The computation could be a heavy one or time sensitive (based on time, currency exchange rates and other). Then you would need to save the value in a database column (a.k.a freezing) and in the future read the value from the field rather than the method., (*3)

The Freezable behavior allows you to do exactly that in an easy way. The freeze(), unfreeze() and is_frozen() methos give you the convenience to easily get either the dynamically computed or the frozen value when needed., (*4)

Usage

It has 3 parameters associations, parent and fields, (*5)

``` php class Some_Model extends Jam_Model {, (*6)

public static function initialize(Jam_Meta $meta)
{
    $meta
        ->behaviors(array(
            'freezable' => Jam::behavior('freezable', array(
                'fields' => 'price',
                'parent' => 'some_parent_model',
                'associations' => array('some_child', 'some_children'),
            )),
        ));
}
//...

}, (*7)


That means that whenever the model is *frozen* then the field named `price` will be assigned the value of the method `price()`. And all the associations will be also *frozen*. The associations themselves have to be *freezable* (have the Freezable behavior attached) in order for this to work. And the `price()` method, as well as any other fields, have to take into account the value of the field. E.g. ``` php public function price() { return $this->price ? $this->price : $this->compute_price(); }

The parent association is used in order to find the value of is_frozen, so that only one model holds the value of the flag. So that if you call is_frozen() on a freezable that has a parent, then it will get that value from the parent., (*8)

Details

TODO: add note about validation TODO: add more examples, (*9)

License

Copyright (c) 2013 OpenBuildings, Inc. Developed by Ivan Kerin as part of clippings.com., (*10)

Under BSD-3-Clause license, read LICENSE file., (*11)

The Versions

09/04 2014

dev-master

9999999-dev https://github.com/OpenBuildings/jam-freezable

Freeze dynamically computed values in the database using Jam

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

database jam freezing

01/03 2014

0.1.3

0.1.3.0 https://github.com/OpenBuildings/jam-freezable

Freeze dynamically computed values in the database using Jam

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

database jam freezing

14/11 2013

0.1.2

0.1.2.0 https://github.com/OpenBuildings/jam-freezable

Freeze dynamically computed values in the database using Jam

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

database jam freezing

14/11 2013

0.1.1

0.1.1.0 https://github.com/OpenBuildings/jam-freezable

Freeze dynamically computed values in the database using Jam

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

database jam freezing

13/11 2013

0.1.0

0.1.0.0 https://github.com/OpenBuildings/jam-freezable

Freeze dynamically computed values in the database using Jam

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

database jam freezing