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

[eluser]m4rw3r[/eluser]
I've also enabled edit permissions for visitors, so if you have something interesting about IgnitedRecord (examples, how to use it with other libraries, behaviours, etc.) please create a wiki page.

[eluser]Heli[/eluser]
Hello, first sorry for my english.
Second, I've got problem: I downloded IR 0.2 from link
and I tried to done "Quick Start", but at first I've got same error as stensi:
Quote:
Code:
user with id #1: me
user me belongs to groups:
A Database Error Occurred
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 'WHERE `id` IN ('1', '1', '2', '2')' at line 2
SELECT * WHERE `id` IN ('1', '1', '2', '2')

Then I've read the post of m4rw3r Posted: 28 August 2008 10:24 AM and desided to took last version of IR from SVN, it was 117 revision. And after that I've got another error:

Code:
A Database Error Occurred

The query you submitted is not valid.

[eluser]Heli[/eluser]
And this is my Controller:
Code:
class User_controller extends Controller{
        function __construct(){
            parent::Controller();
        }
        
        function index(){
            $this->load->model('ignitedrecord/ignitedrecord');
            $this->load->model('user');
            $this->load->model('group');
            
             // 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');
            $test = $related_recs->get();
            // 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>';
            }
        }
    }
and Models:
Code:
class User extends IgnitedRecord{
        var $table = 'users';
        var $has_and_belongs_to_many = 'groups';
    }

Code:
class Group extends IgnitedRecord{
        var $table = 'groups';
        var $has_and_belongs_to_many = 'users';
    }

[eluser]m4rw3r[/eluser]
Can you post the query, so I can see what's wrong?

[eluser]Heli[/eluser]
Query is empty.

[eluser]m4rw3r[/eluser]
Oh, now I see!

Your code here messes things up:
Code:
$related_recs =& $rec1->related('groups');
$test = $related_recs->get();
// go! fetch!
foreach($related_recs->get() as $r)

The first call to get() runs the correct query and then it resets the $related_recs object.
The second gets an empty query because of this (an empty query object).

So the solution is to either remove the $test = $related_recs->get(); line or replace the second $related_recs->get() with $test.

I'll add an error message for those occasions in the future.

[eluser]the ronald[/eluser]
First off. I have to say great job on IgnitedRecord...

When doing an update or an insert ie:
Code:
$this->examplemodel->new_record($array)->save();
everything works great. I was wondering if there is a way to pass native mysql function through the save/update. I have googled this topic like crazy and have found this link:http://ellislab.com/forums/viewthread/83215/ however I can't see how it relates with how IR works.

What I am wanting to do is pass the mysql NOW() function through.

So in the array it would be something like:
Code:
$array['firstname'] = 'John';
$array['lastname'] = 'Doe';
$array['insert_date'] = 'NOW()';  //this is a datetime field in the db; this won't work because of the quotes. But out of the quotes php will try and parse it as a function.
$this->examplemodel->new_record($array)->save();

Thanks in advance for your help...

[eluser]the ronald[/eluser]
Well I think I answered my own question.

Code:
$array['first_name'] = 'John';
$array['last_name'] = 'Doe';
$this->examplemodel->db_set('insert_date', 'NOW()', FALSE);
$this->examplemodel->new_record($array)->save();

This seemed to work for me. Is this the correct way of handling mysql native function through IR? If not I would love to see a different approach...

[eluser]Heli[/eluser]
m4rw3r

Thanks to you. Now it's work.

[eluser]m4rw3r[/eluser]
I see that I need to come up with a neat way to say that a certain value shouldn't be escaped.

One way is to set it as a property in the model:
Code:
class Foo extends IgnitedRecord{
    var $columns = array('not_escaped' => array('escape' => false),
                         ...);
}
But then you may not want to save it unescaped every time, and it seems like unnecessary cluttering in the $columns property
(not if I add something like Datamapper's auto table creation Smile).

Another way is to add a method and property to the IR_record:
Code:
$post = $this->post->new_record();
$post->unescaped('date', 'NOW()');

I dunno which one I should choose, what do you think?
And if you have other solution, don't hesitate to suggest it.

The reason this is needed is that every record should be independent (ie. the model (or sql-lib) shouldn't contain record data, which is the case with the current workaround, see Ticket).

Also I need to refactor the relation code again, because of the "through" relation type *sigh*.
This won't affect the current relation fetching/defining api at all.




Theme © iAndrew 2016 - Forum software by © MyBB