ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

DataMapper 1.6.0

September 05, 2008 12:32pm

Subscribe [115]
  • #241 / Nov 06, 2008 6:20am

    ___seb

    4 posts

    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 :
    ———

    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

    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

    if(substr($item,-1,1) == '*')
            {
                return $item;
            }

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

  • #242 / Nov 06, 2008 7:00am

    abmcr

    254 posts

    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

  • #243 / Nov 06, 2008 12:44pm

    OverZealous

    1030 posts

    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.

  • #244 / Nov 08, 2008 3:33am

    Boyz26

    28 posts

    Can someone tell me if there is a performance difference between:

    (1)

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

    vs
    (2)

    $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!

  • #245 / Nov 08, 2008 3:22pm

    OverZealous

    1030 posts

    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.

  • #246 / Nov 10, 2008 6:39am

    palZ

    7 posts

    Download link was down!

  • #247 / Nov 10, 2008 8:22am

    Matthew Lanham

    145 posts

    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:

    //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

  • #248 / Nov 10, 2008 8:28am

    Matthew Lanham

    145 posts

    Ignore the last comment i had put the plural tasks into the has_many on the wedding model….

  • #249 / Nov 10, 2008 1:39pm

    OverZealous

    1030 posts

    @Matthew Lanham
    I can’t tell you how many times that has tripped me up!  :cheese:

  • #250 / Nov 10, 2008 2:28pm

    Matthew Lanham

    145 posts

    @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

  • #251 / Nov 11, 2008 12:49pm

    amrnt

    39 posts

    how can i make a Relation without using rated_table ??

    I have (posts) table and (categories) table ..

    ... category has many posts ...
    ... posts belong to category ...

    categories -
    -id
    -name

    posts -
    -id
    -title
    -body
    -category_id

    how can i make this relation with this GREAT LIBRARY (DATAMAPPER) from the begin??

    thanks in advance!!!

  • #252 / Nov 11, 2008 3:45pm

    OverZealous

    1030 posts

    You can’t.  As described in the documentation, DM requires a joining table for each relationship - even one-to-one or one-to-many relationships.

  • #253 / Nov 11, 2008 4:30pm

    amrnt

    39 posts

    You can’t.  As described in the documentation, DM requires a joining table for each relationship - even one-to-one or one-to-many relationships.

    oh, thanks ... but what about the performance?, is it normal to use a join table ?

  • #254 / Nov 11, 2008 4:35pm

    OverZealous

    1030 posts

    I’m not sure what you mean by “normal”.  Using join tables is really a DB admin’s preference.  (I usually handle relationships the way you mention, but I believe the development gains in using DM out-weigh the performance differences.)

    Performance depends on your database.  Most databases perform joins very quickly, and you still are sending a single query to the database server.

    Personally, I think PHP is going to have more of an issue performance-wise than the queries.  But that’s purely an opinion, not based on fact!

  • #255 / Nov 11, 2008 4:42pm

    amrnt

    39 posts

    thanks man!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases