CodeIgniter Forums
DataMapper 1.6.0 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: DataMapper 1.6.0 (/showthread.php?tid=11358)



DataMapper 1.6.0 - El Forum - 11-06-2008

[eluser]___seb[/eluser]
Ok, thanks for the tip, it guided me to the solve the prob, i removed ->select.

-----
in fact i was using select because without an error occured :
------
Code:
A Database Error Occurred

Error Number: 1054

Unknown column 'bookmarks.*' in 'field list'

SELECT `bookmarks`.`*` FROM (`bookmarks`) LEFT JOIN `bookmarks_tags` ON `bookmarks`.`id` = `bookmark_id` LEFT JOIN `tags` ON `tags`.`id` = `tag_id` WHERE `tags`.`id` = 19

that's why i use ->select. `*` causes the error (mysql 5.0.51a, mysql 5.0.67 and a version beetween thoses) (xampp for linux packages), SELECT `bookmarks`.* would be better (for that mysql version at least).

So I modified the file Codeigniter core file system/database/drivers/mysql/mysql_driver.php
Code:
function _escape_identifiers($item)
    {
        if ($this->_escape_char == '')
        {
            return $item;
        }
    
        if(substr($item,-1,1) == '*')
        {
            return $item;
        }
        if (strpos($item, '.') !== FALSE)
        {
            $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;            
        }
        else
        {
            $str = $this->_escape_char.$item.$this->_escape_char;
        }
        
        // remove duplicates if the user already included the escape
        return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
    }

I just added
Code:
if(substr($item,-1,1) == '*')
        {
            return $item;
        }

Someone may report the problem ... (I'm too new, and don't know if i had to)


DataMapper 1.6.0 - El Forum - 11-06-2008

[eluser]abmcr[/eluser]
I am absolutly new with the Data Mapper; my question is: the data mapper is fully compatible with CI 1.7 ? The validation librarie of CI is equal to libray of DM..
Thank you


DataMapper 1.6.0 - El Forum - 11-06-2008

[eluser]OverZealous[/eluser]
Sorry, that's a new bug introduced between CI 1.7 and DM. stensi - the creator of DM - has been away for a while. I'm sure it will get fixed quickly once he returns.

(That's really a bug in CI, if you ask me. It shouldn't escape * on queries.)

@abmcr
As you can see above, there is a bug between the two projects as of right now, at least using MySQL as the DB. I haven't upgraded my PostGreSQL project yet.


DataMapper 1.6.0 - El Forum - 11-08-2008

[eluser]Boyz26[/eluser]
Can someone tell me if there is a performance difference between:

(1)
Code:
$b = new Book();
$b->where('id', 1)->get();

$c = $b->category->get();
echo $c->id;

$s = $c->student->get();
echo $s->id;
vs
(2)
Code:
$b = new Book();
$b->where('id', 1)->get();

$c = $b->category->get();
echo $c->id;

$s = new Category();
$c->where('id', $c->id)->get()->student->get();
echo $s->id;

I have been struggling to get the rule of thumb when or when not to do a 'new'. Thanks!


DataMapper 1.6.0 - El Forum - 11-08-2008

[eluser]OverZealous[/eluser]
In the second case, you are unnecessarily creating a new object.

DM has to create a new object internally with the $b->category, so you've already created the object. The only reason to duplicate the object like that is if you needed multiple, but different queries with the relationship. And that probably doesn't happen very often.


DataMapper 1.6.0 - El Forum - 11-10-2008

[eluser]palZ[/eluser]
Download link was down!


DataMapper 1.6.0 - El Forum - 11-10-2008

[eluser]Matthew Lanham[/eluser]
Hey i'm really loving DataMapper,

Got a question regarding relationships...

I have a User who has one Pet who has many Tasks which has many Notes

Heres my code:
Code:
//Get the user
$user = new User();
$user->where('id', $this->session->userdata('user_id'))->get();
//Get the pet
$user->pet->get();
//Count the tasks
$user->pet->task->select('COUNT(*) as count')->get();
//Echo the number of tasks
echo $user->pet->task->count;

But it doesn't seem to accept the select statement, is it possible to do this or am i just going mad for no reason?

Heres the error:
Call to a member function get() on a non-object


DataMapper 1.6.0 - El Forum - 11-10-2008

[eluser]Matthew Lanham[/eluser]
Ignore the last comment i had put the plural tasks into the has_many on the wedding model....


DataMapper 1.6.0 - El Forum - 11-10-2008

[eluser]OverZealous[/eluser]
@Matthew Lanham
I can't tell you how many times that has tripped me up! :cheese:


DataMapper 1.6.0 - El Forum - 11-10-2008

[eluser]Matthew Lanham[/eluser]
@OverZealous.com
Pain in the ass eh !!! so simple

I've found issues when using WEEK, MONTH, DAY in where statements because its doing pets.WEEK(pets.due) = 45 instead of WEEK(pets.due) = 45, i've put some code in to remedy but might be worth noting for future releases or maybe i am missing something