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

[eluser]m4rw3r[/eluser]
Your method is a good one, it is performing well. But it has a drawback, it can only extract data from saved objects, and the __data array will only be updated on save.

You can instead use the native method IR_Record::get_data() to get the data of the object in an array format.

[eluser]tpchris[/eluser]
I'll give that a try. Thanks for the response!

[eluser]helmutbjorg[/eluser]
I'm using a through relationship and am using join related to get the object. How do i go about obtaining the properties of the object that the relationships are working through as well?

If i try to do a join_related on the through table then I get a database error telling me I don't have a unique table/alias.

In my example I have a Product which has a Device which has a Manufacturer.
Code:
$this->product->has_one('manufacturer')->through('device');
$products = $this->product->join_related('manufacturer')->find_all();
foreach($products as $p) {
    echo $p->manufacturer->name;
}

But what i really need is
Code:
$this->product->has_one('manufacturer')->through('device');
$products = $this->product->join_related('device')->join_related('manufacturer')->find_all();
foreach($products as $p) {
    echo $p->device->model;
    echo $p->manufacturer->name;
}

The first query accesses the devices table but unfortunately doesn't select the device data too! How do I get ignitedrecord to return the device info as well as the manufacturer?

[eluser]m4rw3r[/eluser]
I'm sorry, but IgnitedRecord does not have support for (automatic) multi-level joins of relations for the moment (my new ORM does, but it uses a different structure which means that I cannot port it as easy).

The lower example you made seems to work from a quick glance (remember, I haven't had a look at the code of IR in several months, have been really busy with work), but I don't know for now.

[eluser]helmutbjorg[/eluser]
That's all good. Ignitedrecord is amazing anyway. It's not that big a loss to simply fall back to Active record for the complex queries.

What is your 'new ORM' by the way?

[eluser]m4rw3r[/eluser]
My new ORM is ready to use, but I still have a long way to go (if I want it to be a competitor to Doctrine and Propel, which I want).
It uses normal PHP objects which are mapped to the database, and is also a lot faster and more flexible than IgnitedRecord (not in all respects, but in most).

It does not replace the models as IgnitedRecord does, instead its only purpose is to map the objects to the database, andlets the "real models" call it to fetch the objects. This makes for fewer disruptions in the MVC architecture of an existing framework.
My new ORM also uses code generation to generate highly customized code for each of the objects, making the performance a lot better than IgnitedRecord, the sql query builder is also optimized for speed.

You can say that I learned from the "mistakes" I made when I designed IgnitedRecord.
The new ORM is a lot more true to the DataMapper pattern and also a lot more decoupled.

BTW, it will be compatible with almost any PHP framework, including CodeIgniter (it has its own database abstraction, however).

PS. I need to write a bit more on the manual, then I'll create a website (more likely "just a forum") for it.

[eluser]Unknown[/eluser]
I'm having trouble saving related data.
I have an 'ideas' table which HABTM 'tags' table and I want to add a new 'idea' with many 'tags'.
I've read through all of the manual and still don't have a good idea of what the correct method of doing this looks like.
Here's what I have:

idea_model.php:
Code:
<?php
class Idea_model extends IgnitedRecord {
    var $habtm = 'tags';
}
?>

tags_model.php:
Code:
<?php
class Tag_model extends IgnitedRecord {
    var $habtm = 'ideas';
}
?>

ideas.php:
Code:
<?php
$this->load->database();
...
function test() {
$this->load->orm('idea_model');
        $idea = $this->idea_model->new_record();
        $idea->title = 'test';
        $idea->description = 'test';
        $tags = array('big', 'bigger', 'huge');
        $this->load->orm('tag_model');
        foreach ($tags as $tag)
        {
            $idea->add('tags', $this->tag_model->new_record(array('name' => $tag)));
        }
        $idea->save();
}
?>

I have a linking table 'ideas_tags' as well.

Two problems:
1. The first tag (e.g. 'big') never gets put into the database but the others do.
2. No records ever get put into the 'ideas_tags' table.

Any ideas what's going wrong here?
Thanks in advance. I appreciate all of the work you have put into this library, Martin.

[eluser]helmutbjorg[/eluser]
I am getting the following error from this simple code:

Code:
$this->ad->order_by('id', 'random')->find_all();

Code:
A PHP Error was encountered
Severity: Warning
Message: implode() [function.implode]: Bad arguments.
Filename: libraries/Ignitedquery.php
Line Number: 2010

Code:
Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3

SELECT `ads`.* FROM `ads` ORDER BY

Not sure why this is happening. I have tried lots of combos but random doesn't seem to work. Has anybody else used random sorting with IgnitedRecord?

[eluser]Black Buddha[/eluser]
Documenting this in the hopes it saves some other poor soul 3 hours of their life. Porting a MySQL-based application to Postgres, and in between figuring out how to do UUID and DATE_SUB in Postgres and replacing all NOW() calls with CURRENT_TIMESTAMP I ran into significant problems creating relationships between new objects. Turns out that the CI postgres driver is broken (in 1.7.1).

When an INSERT, UPDATE or DELETE occurs the driver saves the statement resource. In the postgres driver this is used by affected_rows() to determine how many rows were affected. However, under certain circumstances the insert_id() function executes a SQL statement. Unfortunately, IgnitedRecord calls insert_id before affected_rows(), changing the statement resource: this causes affected_rows() to return 0 (because the SQL statement executed by insert_id does not affect any rows). When this returns 0 the IgnitedRecord save() function returns false, and All Sorts Of Bad Things Happen preventing constraints from being satisfied.

The answer turned out (after 3 hours of scuffling with print_r() and echo()) to be: save the result_id at the beginning of insert_id() and restore it at the end if it changes. Replace the insert_id() function in the
Quote:database/drivers/postgre/postgre_driver.php
file, and you should be golden.

Code:
function insert_id()
        {
          $old_result_id = $this->result_id;
                $v = $this->_version();
                $v = $v['server'];

                $table  = func_num_args() > 0 ? func_get_arg(0) : null;
                $column = func_num_args() > 1 ? func_get_arg(1) : null;

                if ($table == null && $v >= '8.1')
                {
                        $sql='SELECT LASTVAL() as ins_id';
                }
                elseif ($table != null && $column != null && $v >= '8.0')
                {
                        $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column);
                        $query = $this->query($sql);
                        $row = $query->row();
                        $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq);
                }
                elseif ($table != null)
                {
                        // seq_name passed in table parameter
                        $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table);
                }
                else
                {
                        return pg_last_oid($this->result_id);
                }
                $query = $this->query($sql);
                $row = $query->row();
                $this->result_id = $old_result_id;
                return $row->ins_id;
        }

[eluser]dcunited08[/eluser]
[quote author="m4rw3r" date="1248410301"]My new ORM is ready to use, but I still have a long way to go (if I want it to be a competitor to Doctrine and Propel, which I want).
It uses normal PHP objects which are mapped to the database, and is also a lot faster and more flexible than IgnitedRecord (not in all respects, but in most).[/quote]

So is IgnitedRecord a dead project?




Theme © iAndrew 2016 - Forum software by © MyBB