EllisLab text mark
Advanced Search
1 of 38
1
   
IgnitedRecord 1.0 pre-release
Posted: 30 April 2008 11:11 AM
Avatar
Joined: 2006-08-03
671 posts

IgnitedRecord is a relation handling ORM library, reminding a bit of Ruby on Rails’ ActiveRecord implementation.

The goal of IgnitedRecord is to provide an easy to use, easily customizeable, ORM library to CodeIgniter.

Current version: 0.2.0
(pre-release exists, missing a few features: “through” relations, finished form generation, remade and updated manual)

Features

- Easily configurable
- Uses default values if settings are not explicitly set
- Relations:
       Belongs to
       Has Many
       Has One
       Has And Belongs To Many (shorted to habtm)
- Almost as fast as native CI ActiveRecord when using simple queries, faster when using more complicated ones!
- When fetching related objects, it is possible to filter, order and modify the query in a large quantity of ways
- Belongs To and Has One relations can be fetched easily through a JOIN with the help of join_related()
- Behaviours, which can add and modify the functionality of IgnitedRecord
- Hooks and triggers where you can put your own code
- Complete support for PHP 4, no “hacks” or anyting else is required for IgintedRecord to work under PHP 4.
- Method Chaining under PHP 5
- Nested WHERE statements and subqueries, with help from IgnitedQuery
- Partial support for multiple primary keys (relations are not supported, yet)
- A CodeIgniter-style manual, which covers almost all aspects of IgnitedRecord

Benefits
- Repetitious work is minimized.
- You have a finished model base to builld on.
- You don’t have to write SQL if you don’t want to.
- The choice between updates and inserts is automatically determined.
- The result resources are automatically cleaned up, to improve speed and lower memory consumption.
- The code is easier to read

Performance
Compared to CodeIgniter’s ActiveRecord
-1 % to over 200 % speed gain!!

Compared to direct db interaction
-11 % to -3 %

When performing simple queries, it is almost as fast as Ci’s AR, but when performing more advanced queries it is a lot faster than AR.

Example

$this->load->model('ignitedrecord/ignitedrecord');

$this->post IgnitedRecord::factory('posts');
$this->post->belongs_to('user')->fk('author');

$posts $this->post->like('CodeIgniter')
                    ->
order_by('date''desc')
                    ->
join_related('user')
                    ->
find_all();

foreach(
$posts as $post){
    
echo $post->title;
    echo 
$post->user_username;

Screencast with the 1.0-dev: here

Wiki page: CI Wiki
Download: Assembla SVN Browser (possible to download a zip with a link in the right corner)
Assembla project space: IgnitedRecord

 Signature 

RapidDataMapper: My new ORM, is now released!

IgnitedRecord: Old ORM

MPTtree: A model to handle trees in a database.

YAYParser - Yet Another YAML Parser

 
Posted: 30 April 2008 11:17 AM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-10
2937 posts

Good work man. Fantastic contribution wink

 Signature 

URI Language Identifier | Modular Extensions - HMVC | View Object | Widget plugin | Access Control library

 
Posted: 30 April 2008 11:31 AM   [ # 2 ]   [ Rating: 0 ]
Joined: 2006-07-14
4237 posts

I’ve read somewhere else you are making the orm library php4 compatible, is this the one?

 
Posted: 30 April 2008 11:37 AM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2006-08-03
671 posts

Yeah, this is the one.
But you have to comment the __call() methods in both the IgnitedRecord and IgnitedRecord_record classes.
By removing them you only remove the aggregation of behaviours and their helpers.

Example:

$page $this->page->get();
$page->get_children(); // with __call()
$page->tree->get_children(); // without

$about $this->page->xpath('/about/me'); // with __call()
$about $this->page->tree->xpath('/about/me'); // without 

As you see there is no great difference (using the tree behaviour tongue laugh).
Another thing a PHP 4 user might want to change is the ‘= new’ to ‘=& new’.

All that is covered in the manual.

 Signature 

RapidDataMapper: My new ORM, is now released!

IgnitedRecord: Old ORM

MPTtree: A model to handle trees in a database.

YAYParser - Yet Another YAML Parser

 
Posted: 30 April 2008 11:41 AM   [ # 4 ]   [ Rating: 0 ]
Joined: 2006-07-14
4237 posts

Great, i’m going to check this out.

 
Posted: 01 May 2008 11:02 AM   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2007-10-11
480 posts

Using this I’m given the following error if no records are returned:

A PHP Error was encountered
Severity: Notice
Message: Only variable references should be returned by reference
Filename: models/ignitedrecord.php
Line Number: 774

 Signature 

BarrettNewton.com
CartThrob.com

 
Posted: 01 May 2008 02:20 PM   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2006-08-03
671 posts

Ok, thanks for the feedback, the error is fixed in the RC 3.

I have also managed to get my database to work under PHP 4 (couldn’t connect earlier), so I have done some testing and changes so it now works on PHP 4 without changes (I hope all references work as they should and that no more PHP 4 specific errors are present).

And finally I have fixed the hooks system, so passing by reference works for everything.

PS. I was wrong about the need to comment the __call() methods in PHP 4, it isn’t needed (manual is now changed)

 Signature 

RapidDataMapper: My new ORM, is now released!

IgnitedRecord: Old ORM

MPTtree: A model to handle trees in a database.

YAYParser - Yet Another YAML Parser

 
Posted: 01 May 2008 06:04 PM   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2007-10-11
480 posts

RC 3 has a few errors related to the hooks feature.

The hook($name, $data) function requires 2 parameters, and in a few instances, you’re only passing the $name. I set $data=null in the function call… but I didn’t look deep enough to see if that’s going to cause me problems elswhere.

 Signature 

BarrettNewton.com
CartThrob.com

 
Posted: 01 May 2008 06:26 PM   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2006-08-03
671 posts

You are right, a mistake by me (thanks for telling).
The $data parameter is passed to call_user_func_array(), so it should be:

function hook($name,$data = array()){
... 

I guess I concerned myself a bit too much with the passing of all references…

 Signature 

RapidDataMapper: My new ORM, is now released!

IgnitedRecord: Old ORM

MPTtree: A model to handle trees in a database.

YAYParser - Yet Another YAML Parser

 
Posted: 02 May 2008 02:19 AM   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2008-03-02
58 posts

Wow, thanks for the great things here, It’s help me soooo much

 Signature 

Tarichi | Tarichi | Tarichi - Thanks to CI

 
Posted: 02 May 2008 08:20 AM   [ # 10 ]   [ Rating: 0 ]
Joined: 2007-02-13
13 posts

When I try to establish a new relationship between two models I get this error:

A PHP Error was encountered
Severity: Notice
Message: Undefined property: IgnitedRecord_record::$instance
Filename: models/ignitedrecord.php
Line Number: 1180

A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/ignitedrecord.php
Line Number: 1180

This what I’ve done:

$this->load->model("post");
$this->load->model("tag");
        
$rec $this->post->new_record();
$rec->title 'A new post';
$rec->slug    'a-new-post';
$rec->save();
        
$tag $this->tag->new_record();
$tag->name 'Blah';
$tag->save();
           
$post $this->post->find(2);
$tag $this->tag->find_by('name''Blah');
        
$post->add_relationship($tag); 

What am I doing wrong?

 
Posted: 02 May 2008 01:07 PM   [ # 11 ]   [ Rating: 0 ]
Avatar
Joined: 2006-08-03
671 posts

Whoops, I forgot the double underscore before the instance property (had started to move some methods from MPTtree ORM to IgnitedRecord, so I guess I forgot them (MPTtree uses only instance, without underscores)).

Updated the errata.

Thanks!

 Signature 

RapidDataMapper: My new ORM, is now released!

IgnitedRecord: Old ORM

MPTtree: A model to handle trees in a database.

YAYParser - Yet Another YAML Parser

 
Posted: 02 May 2008 01:35 PM   [ # 12 ]   [ Rating: 0 ]
Joined: 2007-02-13
13 posts

Thanks for the fix, m4rw3r; for some reason the following is not working though.

$post->add_relationship($tag); 

I would expect it to create a new record in the posts_tags table, but it doesn’t.


Edit: sorry, my fault, all’s working wonderfully now :D

 
Posted: 02 May 2008 01:56 PM   [ # 13 ]   [ Rating: 0 ]
Avatar
Joined: 2006-08-03
671 posts

Have you defined a has and belongs to many relationship between the two models (it is needed at least for the object where you are calling add_relationship())?
Because it is working fine for me…

// here is the relationship needed, because you establish a relation from a child record of this class
class post extends IgnitedRecord{
    
var $__has_and_belongs_to_many 'tags';
    function 
post(){
        parent
::IgnitedRecord();
    
}
}
// not needed here, but if you want to call $tag_rec->add_relationship($post_rec); you have to define the relation in here
class tag extends IgnitedRecord{
    
var $__has_and_belongs_to_many 'posts';
    function 
tag(){
        parent
::IgnitedRecord();
    
}

Or have you forgotten the double underscores prefixing the properties?

EDIT: Didn’t see that you cleared that up

 Signature 

RapidDataMapper: My new ORM, is now released!

IgnitedRecord: Old ORM

MPTtree: A model to handle trees in a database.

YAYParser - Yet Another YAML Parser

 
Posted: 02 May 2008 02:07 PM   [ # 14 ]   [ Rating: 0 ]
Joined: 2007-02-13
13 posts

Okay I’ve got another problem for you to solve raspberry

I’m trying to delete a record from the database, and see if also the corresponding relationships are deleted too, so I write this:

$post $this->post->find(2);
$post->delete(); 

I get this error:

Message: Invalid argument supplied for foreach()
Filename: models/ignitedrecord.php
Line Number: 933

 
Posted: 02 May 2008 02:17 PM   [ # 15 ]   [ Rating: 0 ]
Avatar
Joined: 2006-08-03
671 posts

Could you post your derived class?
Because everything works fine for me (the delete() method loops all relations and deletes them, so it is something with the relation properties).

 Signature 

RapidDataMapper: My new ORM, is now released!

IgnitedRecord: Old ORM

MPTtree: A model to handle trees in a database.

YAYParser - Yet Another YAML Parser

 
1 of 38
1