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

Have you redefined the id_col property in the Tree class?
Also try changing log and error level, to see what the problem may be.

Smile oh how stupid!!! i wrote a function with the name find() in my model.... that was the error....

Hi... just noticed a problem with the find function. Not sure if it has been discussed but I couldn't find anything on it when searching.

If I write


The query that get's generated is:
SELECT `researchers`.*
FROM `researchers`

Where what I want is:
SELECT `researchers`.*
FROM `researchers`
WHERE  `id` = 0  

It is only when you submit an integer to the function so if i do this then it works
$this->researcher->find('0'); // Note the quote marks

Is this a bug? I think it doesn't make much sense as to why the integer 0 and the string 0 should have different queries generated. Especially when all other numerals have consistent effect on the query. The only reason I ask is because I use in my coding the intval() function of anything I pass to the find function and it defaults to 0.

I've had some problems too with the integer 0 when used in the where() method of IgnitedQuery, which is building the SQL.
I thought I had it fixed (you're using the latest from SVN, right?), but apparently not.

Going to check that problem and see what I can do to fix it.
Sadly I don't have a test suite for IgnitedRecord, and I don't want to write one now (just thinking about the number of tests makes me want to give up).

Don't give up man... Ignitedrecord is the bomb! Put the word out on the forum. I'm sure somebody has some time to help you out with a test suite. Get some volunteer/community efforts on your side. I'll check out the svn as I'm not entirely sure about the version...

Latest SVN worked perfectly. My bad...

No worries, glad that it is working! Smile

Hi, very glad to have an ORM for CI, great works.

Anyway, would you help me a bit since I'm a bit new to ORM.
Case :
we have 2 table :
Person Jobs
======= ============
id(PK) id(PK)
name person_id(FK)
address company
telp company_address

By using traditional query with select and join with single query, we can show result table as simple as this in view :

foreach($results as $r){
echo '<td>' . $r['id'] . '</td>';
echo '<td>' . $r['name'] . '</td>';
echo '<td>' . $r['company'] . '</td>';
echo '<td>' . $r['company_address' . '</td>'];

But I've found that in ORM we should do this way :
$person = $this->Person->find_all();
$related_person = $person->related('jobs');
$person_job = $related_person->get();

So we need 2 foreach, ones for $person, and other for jobs in view, isn't it?
Is there any way to do it on single foreach like we did on traditional join query ?

Thanks, great works again.

[eluser]Jonas G[/eluser]
Hi All

I'm new to IR but I feel it is just what I need. I can't seem to get around the best practices for creating model functions though. I have the following:

class Outcome extends IgnitedRecord {
    var $table = 'enetpulse_outcome';
    var $has_many = array(
                        // bettingoffers
                        array('table' => 'enetpulse_bettingoffer', 'name' => 'bettingoffer', 'fk' => 'outcomeFK')
    var $belongs_to = array(
                        // event
                        array('table' => 'enetpulse_event', 'name' => 'event', 'fk' => 'objectFK'),
    public function get_best_1x2_for_event($event_id)

        $this->where(array('type' => '1x2', 'objectFK' => $event_id, 'object' => 'event'));

        $outcomes = $this->get();

        // $outcomes = $this->outcome->where(array('type' => '1x2', 'objectFK' => $event_id, 'object' => 'event'))->select('id')->limit(1)->get();

        $output = array();

        if ($outcomes) {
            foreach ($outcomes as $o) {
                $bettingoffers = $o->related('bettingoffer')->select('odds', 'odds')->order_by('odds', 'desc')->limit(1)->get();

                foreach ($bettingoffers as $b) {
                    $output['odds'] = $b->odds;
                    $output['provider'] = $b->providerFK;
            return $output;

        return false;

function index()
        $this->load->model('ir/outcome', 'outcome');
        $this->load->model('ir/bettingoffer', 'bettingoffer');
        $data['next_events'] = $this->Frontpage_model->get_next_events(7);
        foreach ($data['next_events'] as $event) {
            $data['odds'][$event->id] = $this->outcome->get_best_1x2_for_event($event->id);

An Error Was Encountered

IgnitedRecord: Method related is not found.
Called on line 36 in /Users/jgrau/Sites/hidden/app/models/ir/outcome.php.

The above code seemed to work when being run from a controller but not from the model.

What is the deal when working with IR functions from the IR models?
I can't seem to find any of this in the user guide(?)
Is it better practice to move these kind of functions to a library?



Using the join_related method:
(I'm assuming a person has one job)
$persons = $this->Person->join_related('job')->find_all();

foreach($persons as $person)
    echo $person->id;
    echo $person->name;
    echo $person->job->company; // if it was a has many relation, jobs would be an array
    echo $person->job->company_address;

// job is also a record object, making it easy to edit and save
// $person->job->company = 'Some other'; // someone else hired him!
// $person->job->save();

Using the query builder to create a traditional join query:
$persons = $this->Person->join('jobs', 'persons.id = jobs.person_id')->select('company, company_name')->findAll();

foreach($persons as $person)
    echo $person->id;
    echo $person->name;
    echo $person->company;
    echo $person->company_address;

Theme © iAndrew 2016 - Forum software by © MyBB