Welcome Guest, Not a member yet? Register   Sign In
ActiveRecord inspired ORM
#1

[eluser]m4rw3r[/eluser]
I've finished an ORM model which I would like to have some comments on.
It is inspired by ruby's ActiveRecord and it should be very customizable (setting tablenames, foreign key columns, etc.), yet easy to use (assumes some default values if you don't explicitly supply them).
It has currently support for Belongs To, Has Many, Has One and Has And Belongs To Many relationships.
It should be completely PHP 4 compatible (Haven't got the opportunity to test, can somebody please verify that it woks on PHP 4?)
When I am confident that everything works as it should, I will integrate MPTtree and this ORM (I will still have an ORM-less variant of MPTtree).

I currently regard this model as a release candidate, so I have not written any manual or anything, but I think you can figure it out from all the comments in the file.

Wiki download: ORM_by_m4rw3r_RC1

Example:
Code:
// model 1
class thread extends ORM{
    var $__has_many = 'posts'; // you need to define relationships before you call the constructor of ORM
    // it assumes that the model is 'post' (if it exists) and that the foreign key is 'threads_id'
    function page(){
        parent::ORM();
    }
}
// model 2
class post extends ORM{
    // here I specifically define a model and a foreign key for the users table
    var $__belongs_to = array('threads','users' => array('table' => 'users','col' => 'author_id'));
    function post(){
        parent::ORM();
    }
}
// controller
$this->load->model('ORM'); // or include the Model class and orm.php in another way
$this->load->model('thread'); // no need to load the post model, the ORM class loads it if needed
$obj = $this->thread->find(1); // find by id
$obj->load_rel(); // loads all relationships for this record
$obj->posts[0]->load_related('threads'); // loads all related threads in the first post (array is empty / false if no related are found)


Messages In This Thread
ActiveRecord inspired ORM - by El Forum - 04-05-2008, 12:50 PM
ActiveRecord inspired ORM - by El Forum - 04-05-2008, 02:29 PM
ActiveRecord inspired ORM - by El Forum - 04-06-2008, 06:35 AM
ActiveRecord inspired ORM - by El Forum - 04-06-2008, 09:13 AM
ActiveRecord inspired ORM - by El Forum - 04-07-2008, 03:27 AM
ActiveRecord inspired ORM - by El Forum - 04-07-2008, 07:01 AM
ActiveRecord inspired ORM - by El Forum - 04-08-2008, 06:14 AM
ActiveRecord inspired ORM - by El Forum - 04-08-2008, 09:32 AM
ActiveRecord inspired ORM - by El Forum - 04-10-2008, 05:25 AM
ActiveRecord inspired ORM - by El Forum - 04-10-2008, 05:54 AM
ActiveRecord inspired ORM - by El Forum - 04-10-2008, 06:00 AM
ActiveRecord inspired ORM - by El Forum - 04-10-2008, 07:22 AM
ActiveRecord inspired ORM - by El Forum - 04-19-2008, 04:15 AM
ActiveRecord inspired ORM - by El Forum - 04-22-2008, 10:23 PM
ActiveRecord inspired ORM - by El Forum - 04-23-2008, 12:58 AM
ActiveRecord inspired ORM - by El Forum - 04-23-2008, 11:04 AM
ActiveRecord inspired ORM - by El Forum - 04-23-2008, 09:08 PM
ActiveRecord inspired ORM - by El Forum - 04-24-2008, 02:43 AM
ActiveRecord inspired ORM - by El Forum - 04-24-2008, 03:29 AM
ActiveRecord inspired ORM - by El Forum - 04-24-2008, 11:26 AM
ActiveRecord inspired ORM - by El Forum - 04-24-2008, 12:08 PM



Theme © iAndrew 2016 - Forum software by © MyBB