ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

IgnitedRecord 1.0 pre-release

April 30, 2008 11:11am

Subscribe [66]
  • #1 / Apr 30, 2008 11:11am

    m4rw3r's avatar

    m4rw3r

    647 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

  • #2 / Apr 30, 2008 11:17am

    wiredesignz's avatar

    wiredesignz

    2882 posts

    Good work man. Fantastic contribution 😉

  • #3 / Apr 30, 2008 11:31am

    xwero

    4145 posts

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

  • #4 / Apr 30, 2008 11:37am

    m4rw3r's avatar

    m4rw3r

    647 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 😛).
    Another thing a PHP 4 user might want to change is the ‘= new’ to ‘=& new’.

    All that is covered in the manual.

  • #5 / Apr 30, 2008 11:41am

    xwero

    4145 posts

    Great, i’m going to check this out.

  • #6 / May 01, 2008 11:02am

    Chris Newton's avatar

    Chris Newton

    440 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

  • #7 / May 01, 2008 2:20pm

    m4rw3r's avatar

    m4rw3r

    647 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)

  • #8 / May 01, 2008 6:04pm

    Chris Newton's avatar

    Chris Newton

    440 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.

  • #9 / May 01, 2008 6:26pm

    m4rw3r's avatar

    m4rw3r

    647 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…

  • #10 / May 02, 2008 2:19am

    srobet's avatar

    srobet

    53 posts

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

  • #11 / May 02, 2008 8:20am

    Andre83

    12 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?

  • #12 / May 02, 2008 1:07pm

    m4rw3r's avatar

    m4rw3r

    647 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!

  • #13 / May 02, 2008 1:35pm

    Andre83

    12 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

  • #14 / May 02, 2008 1:56pm

    m4rw3r's avatar

    m4rw3r

    647 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

  • #15 / May 02, 2008 2:07pm

    Andre83

    12 posts

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

    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

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases