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 ORM v1.8.2

November 30, 2011 3:43pm

Subscribe [100]
  • #166 / Feb 18, 2012 7:44am

    NiconPhantom

    50 posts

    Hi guys,

    I wasn’t using DataMapper before, but I really like the functionality of it and I am in process of implementation.

    I have one small question, if I’ll work with DB + DataMapper ORM, will it auto escape all the queries like it’s implemented in Active Record?

    Thanks a lot,

    Alex

  • #167 / Feb 18, 2012 7:58am

    WanWizard

    4475 posts

    Datamapper actually uses CI’s database classes, including “active record”, to access the database.

    So yes, everything CI does, Datamapper does too.

  • #168 / Feb 18, 2012 8:01am

    NiconPhantom

    50 posts

    Datamapper actually uses CI’s database classes, including “active record”, to access the database.

    So yes, everything CI does, Datamapper does too.

    Thank you WanWizard for the reply and specially for very great product!

    Alex

  • #169 / Feb 18, 2012 8:43am

    toopay

    1583 posts

    “Active Record” term in CI, was misplaced terminology, dont you think WanWizard? I will call it “query builder”, with extra object hydrator method.

  • #170 / Feb 18, 2012 8:58am

    WanWizard

    4475 posts

    Absolutely. I actually have that on one of my slides for CICONF in about an hour… 😉

    We’ve proposed to Pascal Kriete last night to rename it to QB, but I think it was “lost in beer” somewhere…

  • #171 / Feb 18, 2012 2:34pm

    NiconPhantom

    50 posts

    Hi all,

    I have yet another small question… I have hierarchical menu with relationship between id and parent_id, I have created model like that:

    class menu_model extends DataMapper {


    var $table = "menu";


    var $has_one = array(

    'parent' => array(
    'class' => 'menu',
    'other_field' => 'pid'
    )
    );

    var $has_many = array(

    'child' => array(
    'class' => 'menu',
    'other_field' => 'id'
    )
    );

    function __construct()
    {
    parent::__construct();
    }
    }


    and inside the controller:

      $c1 = new menu_model();
          $c1->get();

    The problem is that print_r($c1,2) is returning not only DB content, but language translations and other staff as well, the data looks like few pages long array. Is it normal or I am doing something incorrectly?

  • #172 / Feb 19, 2012 2:59am

    WanWizard

    4475 posts

    Because Datamapper uses CI as much as possible, var_dump() and print_r() show a lot of information related to linked CI stuff, which is due to CI’s architecture of hooking everything into $this. You don’t have to worry about it, it’s all by reference, so it doesn’t take up (much) space. But it makes debugging more complex.

    What I usually do is to load the ‘array’ extension (I actually do that by default), so you can do

    // dump the current object
    var_dump($c->to_array());
    // dump all loaded objects
    var_dump($c->all_to_array());
  • #173 / Feb 20, 2012 7:43am

    Maglok

    402 posts

    I like that, it is a nice dump of the object. Is there an easy way to also dump all the objects that the current object has? Without needing to write a foreach for every one etc?

    If a Person has_many Friends. This won’t dump the friends.

    Just wondering. Else I’ll write something myself, cause this is indeed handy.

  • #174 / Feb 21, 2012 4:19am

    WanWizard

    4475 posts

    That is exactly what all_to_array() does.

  • #175 / Feb 21, 2012 4:30am

    Maglok

    402 posts

    For that list of objects.

    Example: 10 people are 10 instances of Person. It would show all 10 Person objects. But if each Person has an instance of a Pet class, it does not show those.

  • #176 / Feb 21, 2012 6:56am

    WanWizard

    4475 posts

    Currently to_array() and all_to_array() will add an array of id’s when loaded relations are detected.

    So if a Person would have a relation called ‘pet’, and there are 3 pets loaded, the array entry for that Person would contain ‘pet’ => array(1,5,12), assuming those are the id’s of the loaded pets.

    Not including them completely was done on purpose, to limit the size of the array.

  • #177 / Feb 21, 2012 7:09am

    Maglok

    402 posts

    That makes sense. In this case I’d love to see them, so I am just writing a little function for it. 😊 Keep up the good work.

  • #178 / Feb 21, 2012 11:26am

    WanWizard

    4475 posts

    You could just use the to_array() method in the extension, copy it to a new method, and replace the part where the id is stored in the array by a recursive call to to_array().

    Then copy all_to_array() too, and have it use the new methodname you’ve chosen.

  • #179 / Feb 22, 2012 2:31am

    Maglok

    402 posts

    I was thinking of something like that, thanks for the tip. 😊 Useful.

  • #180 / Feb 22, 2012 8:49pm

    Ok I am having another strange issue with this version of DataMapper any ideas?

    Unexpected PHP error [Accessing static property Band::$config as non static] severity [2048] in [/application/libraries/datamapper.php line 6563]

    The code still works fine but that error is being generated.

    Edit: It only happens when using a DataMapper model outside of a controller. If I use it from a controller it works fine.

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

ExpressionEngine News!

#eecms, #events, #releases