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

OH! Thanks!!

I'll try it!!

Now, I was trying this:

class User extends IgnitedRecord {
    var $belongs_to = "province";
    var $has_one = "userdetail";

    const NICKNAME_MIN_LENGTH = 4;
    const NICKNAME_MAX_LENGTH = 12;
    const PASSWORD_MIN_LENGTH = 4;
    const PASSWORD_MAX_LENGTH = 25;
    const EMAIL_MAX_LENGTH = 30;

    function __construct()

        $this->add_hook(array('pre_get', 'pre_find', 'pre_find_by', 'pre_find_all', 'pre_find_all_by'), array($this,'_load_query_user') ) ;

        $this->add_hook(array('post_get', 'post_find', 'post_find_by'), array($this,'_load_object_user') ) ;


    public function _load_query_user(&$model)

    public function _load_object_user(&$rec)
        $rec->avatar =& Avatar_model::factory($id);


And not works Sad

Is showing a notice error on line 515 of ignitedrecord.php

function add_hook($name, $function, $priority = 10)
        foreach( (Array) $name as $hook)
            $this->hooks[$name][$priority][] = $function; //<-- line 515


Hi there,

quick question.

Why does calling save() on an object which hasn't had any properties modified cause an ERROR in the codeigniter log?

Just curious? (Im now checking to see whether the property has been modified first)

Is this by design?

thanks again

I've fixed that error with the add_hook() method, and also lowered the error level to debug for the event when save() does not save the object because it is unchanged.

m4rw3r, I really apreciate your support!

Thanks !!

I can't understand this:

class Vehicle extends IgnitedRecord {
    var $belongs_to = array('vehiclebrand','vehicletype');

    function __construct()

        // simulate autoload of model relationships
        $this->add_hook(array('pre_get', 'pre_find', 'pre_find_by', 'pre_find_all', 'pre_find_all_by'), array($this,'_load_query_vehicle') ) ;

        // add properties after record object is created
        $this->add_hook(array('post_get', 'post_find', 'post_find_by'), array($this,'_load_object_vehicle') ) ;


    public function find_most_popular()
        return $this->find_all();

    public function _load_query_vehicle(&$model)


    public function _load_object_vehicle(&$rec)


/* End of file vehicle.php */

In vehicle controller method index, I can list the vehicles and his brand name with vehiclebrand_name property. GOOD!


Then in vehicle controller method brand (I want to list the vehicles of a brand) :

     * Brand page
    function brand($brand_id) {

        $this->output->enable_profiler = TRUE;
        $brand = $this->vehiclebrand->find($brand_id);

        if($brand != FALSE)
            $data['title'] = $brand->name;
            $data['brand_vehicles'] = [b]$brand->related('vehicles')->get();[/b]
            $this->template->write_view('content', 'vehicles/brand',$data);

Why I get this error for each vehicle object?

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message: Undefined property: IR_record::$vehiclebrand_name</p>
<p>Filename: helpers/vehicle_helper.php</p>
<p>Line Number: 12</p>

Are hooks executing when I use ->related('vehicles')->get() ??

I tried not to use hooks too, and I tried to extend find_by and find_all_by methods with no result Sad.

What I'm missing??

Hooks does not execute with related(), which is something that I might need to implement.

So you have to call related('vehicles')->join_related('vehiclebrand', 'name')->get() instead.


When I call


I get a strange SQL syntax error:

SELECT `vehiclebrand`.`vehicles` AS `vehiclebrand_vehicles`, `vehiclebrand`.`id` AS `vehiclebrand_id`, `vehiclebrand`.`` AS `vehiclebrand_`, `vehiclebrand`.`IR_record` AS `vehiclebrand_IR_record`, `vehiclebrand`.`Array` AS `vehiclebrand_Array`, `vehiclebrand`.`Array` AS `vehiclebrand_Array`, `vehiclebrand`.`Array` AS `vehiclebrand_Array`, `vehiclebrand`.`Array` AS `vehiclebrand_Array`, `vehiclebrand`.`Array` AS `vehiclebrand_Array`, `vehiclebrand`.`` AS `vehiclebrand_`, `vehiclebrand`.`Array` AS `vehiclebrand_Array`, `vehiclebrand`.`Array` AS `vehiclebrand_Array`, `vehiclebrand`.`Array` AS `vehiclebrand_Array`, `vehiclebrand`.`Array` AS `vehiclebrand_Array`, `vehiclebrand`.`` AS `vehiclebrand_`, `vehiclebrand`.`Array` AS `vehiclebrand_Array`, `vehiclebrand`.`` AS `vehiclebrand_`, `vehiclebrand`.* AS `vehiclebrand_*`, `vehiclebrand`.`` AS `vehiclebrand_`, `vehiclebrand`.`Array` AS `vehiclebrand_Array`, `vehiclebrand`.`Array` AS `vehiclebrand_Array`, `vehiclebrand`.`Array` AS `vehiclebrand_Array`, `vehiclebrand`.`Array` AS `vehiclebrand_Array`, `vehiclebrand`.`Array` AS `vehiclebrand_Array`, `vehiclebrand`.`Array` AS `vehiclebrand_Array`, `vehiclebrand`.`` AS `vehiclebrand_`, `vehiclebrand`.`` AS `vehiclebrand_`, `vehiclebrand`.`` AS `vehiclebrand_`, `vehiclebrand`.`Array` AS `vehiclebrand_Array`, `vehiclebrand`.`Array` AS `vehiclebrand_Array`, `vehiclebrand`.`` AS `vehiclebrand_`, `vehiclebrand`.`Array` AS `vehiclebrand_Array`, `vehiclebrand`.`` AS `vehiclebrand_`, `vehiclebrand`.`` AS `vehiclebrand_`, `vehiclebrand`.`` AS `vehiclebrand_`, `vehiclebrand`.`` AS `vehiclebrand_`, `vehiclebrand`.`` AS `vehiclebrand_`, `vehiclebrand`.`` AS `vehiclebrand_`, `vehiclebrand`.`mysql` AS `vehiclebrand_mysql`, `vehicles`.* FROM `vehicles` JOIN `vehiclebrands` AS `vehiclebrand` ON .vehiclebrand_id = vehiclebrand.id WHERE `vehicles`.`vehiclebrand_id` = '19'

I tried the code, and found that related()'s join_related() method is flawed.
Probably occurred when I implemented the Through relationship.

I have now fixed that error, so update IR and try again.
Hope it works!

(Tell me if it isn't)

SOLVED!! :exclaim:

SELECT `vehiclebrand`.`name` AS `vehiclebrand_name`, `vehicles`.*
FROM `vehicles`
LEFT JOIN `vehiclebrands` AS `vehiclebrand` ON vehicles.vehiclebrand_id = vehiclebrand.id
WHERE `vehicles`.`vehiclebrand_id` = '19'

Thank you! Confusednake:

Hi, i have question about cascade_on_delete, how this should be set up?

public $belongs_to = array(
    'name' => 'my_model',
    'table' => 'my_table',
    'fk'    => 'my_fk',
    'cascade_on_delete' => true

all other things but cascade on delete seem to work.


Theme © iAndrew 2016 - Forum software by © MyBB