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

[eluser]m4rw3r[/eluser]
To make a self referencing relation you have to use the advanced type of defining relations, here is an example:
Code:
// page model, with an adjacency list:
var $has_many = array('name' => 'children', 'table' => 'pages', 'fk' => 'parent_id');

var $belongs_to = array('name' => 'parent', 'table' => 'pages', 'fk' => 'parent_id');

[eluser]cayasso[/eluser]
Hey @m4.. you are the master. Thanks for the help!!!
Smile

[eluser]porky207[/eluser]
Hi, this question is similar to one already had before, I need to add an unquoted expression into the JOIN ... ON section of a join query generated based on HABTM properties. :S

Dealing with geographical features, my database contains arcs and points. One arc has up to 500 points, and a point can belong to several arcs. If I need to retrieve ALL the points related to a particular arc, this works perfectly:

Code:
$arc = $this->Arc->join_related('points')->find(1);
foreach($arc->points as $point){ ... }

The relationship used here is HABTM, and does exactly what I need.

Since this query is used for generating graphics and since there are many arcs and VERY many points, for non-final renders, I want to skip some points. In a hardcoded query, adding
Code:
MOD(point.id,3) = 0
to JOIN ... ON cuts it. I have tried adding it to WHEREs (which is not the best solution) and it gets integrated to the query, but the query dies because of backticks in wrong places.

Is there any way to add such unquoted expression among the relationships-based join conditions of an IR query?

I realize that trying to do this with IR might be pushing the limits of what it can realistically expected to do; I think it is a hell of a good job even if it doesn't accomodate my SQL quirks.

Thank you in any case. /p

[eluser]m4rw3r[/eluser]
You mean that the where() method escapes?
Then just use $escape = false on the where (set the third parameter to false).

To set the ON clause on the JOIN is quite hard, because the query construction of the relations are quite deep down in the call chain.
Maybe it will be possible in a future release, depends on how I add hooks to the relations.

[eluser]porky207[/eluser]
Hi again-

So I've solved it using the WHERE option. I kept getting funny backticks even with the third arg=FALSE, because I was still using the second arg. Now that I've put the ENTIRE expression into the first arg and left the second NULL it works just dandy. Makes sense when you think about it Wink

Thanks!

[eluser]sofbas[/eluser]
Hi, I believe a modification needs to be made to the MY_Loader.php file after the change in the case of the filename.

Line 53 MY_Loader.php should be:
Code:
require_once(APPPATH.'libraries/ignitedrecord/Ignitedrecord.php');

[eluser]m4rw3r[/eluser]
Thanks for spotting that one, it is now fixed!

[eluser]ardinotow[/eluser]
I use modular extensions and have successfully run IR test in "welcome" module. Here is my controller :
Code:
<?php

class Irtest extends Controller {

    function Irtest()
    {
        parent::Controller();    
        $this->load->database();
        $this->load->library('ignitedrecord/ignitedrecord');
        $this->load->orm('user');
    }
    
    function index()
    {
    
        // load the record with id 1
        $rec1 = $this->user->find(1);

        echo 'user with id #1: '.$rec1->name.'<hr>';
        echo 'user '. $rec1->name .' belongs to groups:<br>';

        // now, create a query object that fetches all related groups:
        $related_recs = $rec1->related('groups');

        // go! fetch!
        foreach($related_recs->get() as $r)
        {
            // print their names
            echo $r->name.'<br>';
        }

        echo '<hr> all users:<br>';

        // now fetch all users
        $recs = $this->user->find_all();
        foreach($recs as $r)
        {
            echo $r->name.'<br>';
        }
    
    }
}

/* End of file irtest.php */
/* Location: ./system/application/modules/welcome/controllers/irtest.php */
And my model is:
Code:
&lt;?php

class User extends IgnitedRecord {
    var $has_and_belongs_to_many = 'groups';
}

/* End of file user.php */
/* Location: ./system/application/modules/welcome/models/user.php */
But I failed running the same script as above in my other module. I got this error messages:
Code:
Fatal error: Call to undefined method Loader::orm() in C:\xampp\htdocs\soraksorai\system\application\modules\lowongankerja\controllers\lowongankerja.php on line 15
Why it happens?

[eluser]Muser[/eluser]
Already Have you patched libraries/Controller.php file with the modifications of the wiki?

http://codeigniter.com/wiki/IgnitedRecord_with_HMVC/

[eluser]ardinotow[/eluser]
@Muser: I have used the patch, but still no luck and with the same error message. Could you please post here the full code of modified controller.php cause I'm afraid I paste the patch code on the wrong location. Thx




Theme © iAndrew 2016 - Forum software by © MyBB