Used in...
The following countries:
GROMM is a Relational-Object Mapper for the Masses
I developed GROMM because I was in need of a good ORM for PHP with some special features, like class inheritance support. I searched for it and after a while I decided to develop one for my own and the community.
GROMM is a work-in-progress and the code is currently being tested.
The pre-release "alpha" version is not suitable for usage but you can look at the source code.
Example
Scenario:
- There is a "Carnivore" abstract class that has "Cat" and "Dog" as subclasses.
- Both are related with a 1:1 relationship called "enemy".
- "Mice" is another class that has a N:M relationship with "Carnivore", called "can_eat" (dogs and cats can eat lots of mice).
- Kill-then-eat events are registered using the "eaten_by" relationship between "Carnivore" and "Mice".
- "Mice" and "Carnivore" are child classes of the "Animal" abstract class.
- Some friend animals can seek an alliance with another animal in order to pursue something, like killing an enemy; this is the 1:N "allied" self-relationship of "Animal".
- War is declared using the Animal-to-Animal 1:N "will_kill" relationship.
- Nature rules.
Code:
$bob = Dog.orm_fetch(55); // fetch for Dog table record with id = 55
$ike = Cat.orm_create(); // this Cat ID will be assigned at save time
$bob->enemy = $ike; // ike's "enemy" (1:1 relationship) is automatically set to bob
$killers = array( $bob, $ike ); // $killers is array of (abstract) Carnivore
$mice = Mice.orm_fetch( array(23, 32, 64) ); // fetch multiple rows at a time
list ( $paco, $luis, $hugo ) = $mice; // each mouse has a different personality
foreach ( $killers as $ogre ) { $ogre->can_eat = $mice } // create the N:M (and M:N) pairs
$bob->eaten_by( $hugo ); // a mouse is dead; $paco and $luis are angry and want to kill $bob
$hugo.delete(); // delete from DB and update automatically all its relationships
$mice.array_pop(); // delete $hugo from the array of mice
// alive mice can't kill $bob by themselves; they decide to pact with the cat; $ike agrees
$ike->allied = array( $paco, $luis ); // set the 1:N alliance (Mice.allied is also updated)
$cartel = array( $paco, $luis, $ike ); // a secret forge of animals
foreach ( $cartel as $agent ) { $agent->will_kill( $bob ); } // set the 1:N relationship
$bob->fight(); // as result of executing of this behaviuor, $bob dies... RIP
$bob.delete(); // should be done inside Dog::fight(); $bob's relationships are deleted
unset( $ike->allied ); // destroy the alliance
$paco->save(); $luis->save(); $ike->save(); // the other way is using auto-save
foreach ( $mice as $mouse ) { $mouse->run_to_the_hills(); } // remember $ike? life resumes...
Features
- Complete ORM solution for PHP.
- Clear, easy-to-use minimal syntax.
- Supports OOP class inherithance implemented with a database tables hierarchy scheme.
- Each relationship assignment updates the reverse relationship automatically.
- Relationships named as roles; have a name in class A and other name in the class B.
- Default values for relationships are supported.
- N:M relationships can have attributes.
- Guarantees singleton objects for each record in each PHP/webserver process/instance.
- Hard or soft deletes with unique-index collision avoidance.
- Autosave option (object by object) at end of script execution.
- Configuration is completely decoupled from the component logic.
- Data integrity independent of the RDBMS and ensured among all PHP concurrent processes.
- Doesn't rely on RDBMS reflection; metadata is defined inside the configuration class.
- Framework-agnostic implementation.
- Clear, easy-to-understand and IDE-friendly object oriented source code.
- Free software released under the GNU GPL license.
History
- v.0.0 alpha 1: work-in-progress; currently in testing; available in github.
Contributors
In order of appearance:
- GG :: Gorka G LLONA.
License
This work is licensed under the GNU General Public License (GPL).
Author
Gorka G LLona (profile).
Feedback
Please contact the author for improvements, suggestions and bugs.