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

[eluser]jinfusion[/eluser]
Sorry, The answer you posted to my question is not clear enough for me. I know you are very busy, but I hope you can take a moment to expand on it a bit. The need is to access fields in the join/map table of a many to many rel. Can you run through a simple but full example?

also I am assuming I can use the 'attr' multiple times per definition as I will have more then one attribute in the join table. Is that right?

Thank you, Joel

[eluser]m4rw3r[/eluser]
@jinfusion:

You just put all the different attributes in an array:
Code:
// define:
$habtm = array('table' => 'pages', 'attr' => array('color', 'owner'));

// use:
$record = $this->category->find(/* well, something here */);

$record->add('pages', $a_page_record, array('color' => 'blue', 'owner' => 'me :)'));

foreach($record->related('pages')->get() as $p)
{
    echo "Color: {$p->color}, Owner: {$p->owner}, Name: {$p->name}"; // $p->name is a normal column, the other tow are from the join table
    // you can also filter with the attributes in the join table, just use their attribute name
}
The limit of the habtm relation is that only one relation is allowed between two records (maybe something for my new ORM, allowing it when using attributes?)
Also, keep in mind when naming the attributes so their names doesn't collide with other columns

@paul Apostol:
Can you elaborate?
Preferably a bit of the model code, if you have anything custom (=not using defaults) there, and what errors you are experiencing.

[eluser]Black Buddha[/eluser]
While working with IgnitedRecord, was having a terrible time doing a simple multiple-belongs to relationship: it would consistently throw a constraint violation exception. My relationship looked like this:

Code:
var $belongs_to = array(array('table' => 'account', 'fk' => 'account', 'name' => 'account'),
              array('table' => 'entity', 'fk' => 'entity', 'name' => 'entity'));

and when I tried to set the relationships in the object like so:

Code:
$item->add('entity', $entity);
$item->add('account',$account);

I kept getting a constraint violation. I ended up (after a couple of hours of struggle) realizing that the function establish() in RelProperty.php automatically does a save() on the child, even if the child hasn't been completely configured. I ended up modifying RelProperty.php and changing line 371 from

Code:
return $child->save();

to
Code:
return true;

Is this a known condition and multiple belongs_to relationships with constraints are not supported? It should probably have an option for belongs_to relationships that defers the save(): this would not only be more performant but would allow it to support these sorts of configurations.

[eluser]dcunited08[/eluser]
There is an issue with mssql in Ignitedquery->_protect_identifiers. I fixed by creating a regular expression which matches on two-word items. It can not match on items with 'AS' in it and I am not sure what else it should capture on so I made it as limited as possible. I changed Ignitedquery line 2446 and following to the code below. Any ideas?

Code:
// fixes error with escaped tablename
if(preg_match("/^\b\w+\b\s\b\w+\b$/", $item) > 0){
    return '['.$item.']';
}else{
    return $item; // TODO: How does this affect other identifiers?
}

[eluser]Nabeel[/eluser]
I updated from the 1.0 to the latest one in SVN, hoping that my issue below would be fixed, but found out that this is broke:

Code:
return $this->where('TIMEDIFF (deptime, TIME(NOW())) <= '.$time, '', false);

In the latest SVN version:

Code:
SELECT `schedules`.* FROM `schedules`
WHERE `TIMEDIFF` `(deptime,` `TIME(NOW()))` <= `3600` ORDER BY `deptime` DESC

Whereas in the older 'zipped' one:

Code:
SELECT `schedules`.* FROM `schedules`
WHERE TIMEDIFF(deptime,TIME(NOW()))<=3600 ORDER BY `deptime` DESC

Can't get fetch_all to work either. So now I revert back to the older version:

Code:
public function upcoming_flights($time = 60)
{
    $time = $time * 60;
    return $this->where('TIMEDIFF(deptime,TIME(NOW()))<='.$time, '', false)
        ->order_by('deptime', 'DESC');
}

Code:
$data['upcoming_flights'] = $this->schedules_model->upcoming_flights()->find_all();
echo $this->db->last_query();
        
foreach($data['upcoming_flights'] as $flight)
{
    echo "<br />Departing from {$flight->depicao} to {$flight->arricao}";
}

Reverting to the older version, the query is formatted right, but only one result is being returned, though running the query returns 15.

Not sure if it's a bug, or something I'm doing wrong

[eluser]Nabeel[/eluser]
Nevermind, I didn't supply the key for the schedules_model table. Woops.
But, that brings my next question in - I added the foreign key for a join, but I guess you can't supply a different column in the current table to join on? For instance, instead of joining on ID, it should join on "apikey" in my example.

Man, I'm so used to doing everything by hand, this is new Big Grin

[eluser]ardinotow[/eluser]
Hi, I have a problem with find_all_by_sql. If I use $this->find_all_by_sql('myquery') function, it only showing one record instead of two records. But, If I use codeigniter active records $this->db->query('myquery') it can showing two records. Below is myquery:
Code:
'SELECT COUNT(posts.id) AS posts_count, posts.date_posted
FROM posts
WHERE posts.status = "published"
GROUP BY SUBSTRING(posts.date_posted, 1, 7)
ORDER BY posts.date_posted DESC
LIMIT 10'
This is my controller:
Code:
function wg_archive_list()
    {
        $data['archives'] = $this->post->get_archive();
        $i=0;
        foreach ($data['archives'] as $key => $archive)
        {
            $i++;
        }
        echo 'i='.$i;
    }
This is my model:
Code:
&lt;?php
class Post extends IgnitedRecord {
    var $has_many = array ('comments', 'pictures');

    function get_archive()
    {
        $query = $this->find_all_by_sql('SELECT COUNT(posts.id) AS posts_count, posts.date_posted
        FROM posts
        WHERE posts.status = "published"
        GROUP BY SUBSTRING(posts.date_posted, 1, 7)
        ORDER BY posts.date_posted DESC
        LIMIT 10');
        return $query;
    }    
}
Above controller will showing i=1.
And this is my controller that using codeigniter active record:
Code:
function wg_archive_list()
    {            
        $data['archives'] = $this->db->query('SELECT COUNT(posts.id) AS posts_count, posts.date_posted
        FROM posts
        WHERE posts.status = "published"
        GROUP BY SUBSTRING(posts.date_posted, 1, 7)
        ORDER BY posts.date_posted DESC
        LIMIT 10');
            
        $i=0;

        foreach ($data['archives']->result() as $key => $archive)
        {
                $i++;
        }
        echo 'i='.$i;

    }
Using above controller will showing i=2
Correct answer is i=2.
How to fix this ? Thx

[eluser]m4rw3r[/eluser]
@ardinotow:
You have to select the PK too, IR makes one record per PK.

@Nabeel:
Unfortunately not for the moment, and I don't know how much it is in demand to be able to relate with anything but the PK to an FK.
@all: How usable would it be to relate to anything but the PK?

@Black Buddah:
Something I will take in consideration for my new ORM.

[eluser]ardinotow[/eluser]
Thx again m4rw3r

[eluser]gunter[/eluser]
I have a strange error:
Code:
$this->load->orm("tree");
$rec= $this->tree->find_by("id",$id); // only this does work
$rec= $this->tree->find($id);//  does not work - get a blank page...
with the following code find() will work...
Code:
$this->load->orm();
$this->tree = IgnitedRecord::factory('tree');
do you know whats wrong?




Theme © iAndrew 2016 - Forum software by © MyBB