Welcome Guest, Not a member yet? Register   Sign In
IgnitedRecord 1.0 pre-release

[eluser]amrnt[/eluser]
sorry, but from where i can get it??!
i can only see 0.1.1 and 0.2.0!!

[eluser]Sander Versluys[/eluser]
From the IgnitedRecord homepage. It's is not released yet. But you can get it with svn. If you don't know how that works, you can stick with 0.2 untill it gets released.

[eluser]Sander Versluys[/eluser]
How can I access the methods in the model from an IR_record Object?

Example:
Code:
class User_model extends IgnitedRecord {

    var $has_and_belongs_to_many = 'roles';

    function is_in_role($role) {    
        $roles = $this->get_related('roles')
                       ->get();
        return in_array($role, $roles);
    }
    
}

So when I fetch a user from the database, i can call the is_in_role() method of that object...

Or can this only be accomplished with behaviors? And are the models that are extending the IgnitedRecord class in this way only wrappers for configuration?

Thanks!

[eluser]Jamie Rumbelow[/eluser]
Love it! Well done!

[eluser]dcunited08[/eluser]
Can someone do an alpha release of 1.0? I.e. just put it here or on that site in a zip labeled alpha. I am behind a proxy that doesn't really work too well with svn.

[eluser]m4rw3r[/eluser]
@Sander Versluys:

IgnitedRecord uses the DataMapper pattern (not to be confused with stensi's DataMapper ORM), and the model and data objects are separate classes.
So to add a method to the model, just add it to the model class.

But if you would like to add a method to a record, you have to create a descendant class of IR_record, assign your methods to that class, then set $child_class in the model to the class name:
Code:
class User_model extends IgnitedRecord{
    var $child_class = 'user_record'; // the name of the class to create

    // define some more things here, just as usual
}

class user_record extends IR_record{
    function my_func()
    {
        echo $this->name;
    }
}
This means you can make generic record objects (but more specialized than IR_record), and reuse them with different models.

@dcunited08:

There it is Smile:
http://www.assembla.com/spaces/IgnitedRecord/documents

[eluser]dcunited08[/eluser]
Relations question:

I have 2 tables, one is an items table and one is a machine table. How can I join them so that when I call an item from my items_model, I can load the corresponding machine object?
Code:
class items_model extends IgnitedRecord{
     var $table = 'items';
    var $id_col = 'ID';
}

class machines_model extends IgnitedRecord{
    var $table = 'machines';
    var $id_col = 'ID';
}

I would like to load the items like so (within a items_model method):
Code:
$items = $this->find_all();
$item = $items[0];
$item->related('machines');

Or even have them loaded when I run the original find_all().

[eluser]Sander Versluys[/eluser]
Aha it makes sense now!

m4rw3r you're awesome! :lol: :exclaim:

Thanks!

[eluser]m4rw3r[/eluser]
@dcunited08:

You can call join_related(), then they are joined and fetched with one SINGLE query. Smile (since 1.0)
Saves a lot of queries with has many relations (and habtm too).

So your code (I hope I guessed right about your relations):
Code:
class item_model extends IgnitedRecord{
    var $id_col = 'ID';
    var $belongs_to = 'machine';
}

class machine_model extends IgnitedRecord{
    var $id_col = 'ID';
    var $has_many = 'items';
}

// controller:

// load the machine_model and the item_model
$machines = $this->machine_model->join_related('items')->find_all();

foreach($machines as $m)
{
    echo $m->name;
    foreach($m->items as $i)
    {
        echo $i->name;
    }
}

[eluser]dcunited08[/eluser]
@m4rw3r

How do I set the foreign key (do I have to use the has_many method instead)?
Code:
class item_model extends IgnitedRecord{
    var $id_col = 'ID';
    var $belongs_to = 'machine';
    var $fk = 'machineid'; //does not work but i don't have a column machine_id
}

class machine_model extends IgnitedRecord{
    var $id_col = 'ID';
    var $has_many = 'items';
}


Thank you so much for your quick responses.




Theme © iAndrew 2016 - Forum software by © MyBB