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]
  • #16 / Dec 01, 2011 3:43pm

    WanWizard

    4475 posts

    I have updated the online version of the 1.8.2 zipfiles, with fixes for the errors above, and one reported on the issue tracker (related to loading the form validation library).

  • #17 / Dec 02, 2011 1:01pm

    Spir

    139 posts

    Hi,
    I’m here again with my many to many relationship noobs question.
    What is the best way to load join field when iterating on items.
    Here are the models :

    class Items extends DataMapper {
        public $has_many = array(
            'lang' => array(
                'class' => 'lang',
                'other_field' => 'item',
                'join_self_as' => 'item',
                'join_other_as' => 'lang', would be 'lang_id'
                'join_table' => 'items_langs'
     ),
        );
    }
    class Langs extends DataMapper {
        public $has_many = array(
            'item' => array(
                'class' => 'item',
                'other_field' => 'lang',
                'join_self_as' => 'lang',
                'join_other_as' => 'item', would be 'item_id'
                'join_table' => 'items_langs'
     ),
        );
    }


    Now I’m loading all items and looping on them. I want to display their data and the field “name” which is a data in the joined field (ie. in the table items_langs).

    I have loaded my current language and I want to display the name of the item in my language. What is the best way to do it?

    $items = new Item();
    $items->get();
    
    foreach($items as $item)
    {
        $item->lang->where('id', $default_language->id)->include_join_fields()->get();
        echo $item->lang->join_name;
        // Would be nice to pass related field as param like this :
        $item->include_join_fields($default_language)->get();
    
    }

    Lang is already loaded why loading it again? Any better solution?

  • #18 / Dec 02, 2011 7:47pm

    WanWizard

    4475 posts

    A loop like this runs N+1 queries, which is probably not a good idea.

    I would suggest getting them all in one go with something like:

    $items = new Item();
    $items->include_related('lang')->where_related_lang('id', $default_language->id)->include_join_fields()->get();

    I don’t get why you say that lang was already loaded. I don’t see any code in your snippet that does this twice.

  • #19 / Dec 02, 2011 9:11pm

    azheem

    1 posts

    Update for The Example Code

    Hey, i’m new to ORM, and this is the first ORM i’ve ever learned. I’ve read The DataMapper Manual and it suggested me to try the Example Project which you provided, but unfortunately the code seems not compatible with the latest CI. I’m using CI 2.1.0 and DataMapper 1.8.2.
    I’m sorry for asking this, and i know you must be very busy too, but when will the example code get an update?

  • #20 / Dec 03, 2011 5:08am

    WanWizard

    4475 posts

    The example code hasn’t been looked at since CI 1.7.1. I’m afraid.

    Bringing it up to date is on my todo list, which unfortunately is quite long. I can see if there is a quick fix for the current example application, but I will probably rewrite the example application for DataMapper v2.

  • #21 / Dec 03, 2011 6:25am

    Spir

    139 posts

    A loop like this runs N+1 queries, which is probably not a good idea.

    I would suggest getting them all in one go with something like:

    $items = new Item();
    $items->include_related('lang')->where_related_lang('id', $default_language->id)->include_join_fields()->get();

    I don’t get why you say that lang was already loaded. I don’t see any code in your snippet that does this twice.

    I load the lang based on user in parent controller (MY_Controller).
    Thanks WanWizard.

  • #22 / Dec 03, 2011 2:34pm

    WanWizard

    4475 posts

    @azheem,

    I’ve updated the example application, and added some quick fixes to the htmlform extension to make it work.

    The 1.8.2 download has been updated with these fixes, download it again if you want to try the example.

  • #23 / Dec 04, 2011 9:38pm

    elmizan

    7 posts

    Hi i found some error after try to using example application on codeigniter 2.1.0 and datamapper 1.8.2

    Fatal error: Call to undefined method CI_DB_mysql_driver::dm_call_method() in C:\wamp\www\examples\application\libraries\datamapper.php on line 1113
  • #24 / Dec 05, 2011 3:49am

    WanWizard

    4475 posts

    Then you haven’t read the docs, and didn’t install the bootstrap in your index.php file.

    This is new since 1.8.2, see http://datamapper.wanwizard.eu/pages/installation.html.

  • #25 / Dec 05, 2011 8:49pm

    smartkit

    1 posts

    Same error occur:
    Fatal error: Call to undefined method CI_DB_mysql_driver::dm_call_method() in C:\wamp\www\examples\application\libraries\datamapper.php on line 1113

    Any work fine version with full packaged code base include CI 2.1.0 and DataMapper1.8.2 ?
    We will be greatly appreciated!

  • #26 / Dec 05, 2011 10:10pm

    Mark Price

    24 posts

    You need to add

    /*
     * --------------------------------------------------------------------
     * LOAD THE DATAMAPPER BOOTSTRAP FILE
     * -------------------------------------------------------------------- *
     */
    require_once APPPATH.'third_party/datamapper/bootstrap.php';

    directly before the

    /*
     * --------------------------------------------------------------------
     * LOAD THE BOOTSTRAP FILE
     * --------------------------------------------------------------------
     *
     * And away we go…
     *
     */
    require_once BASEPATH.'core/CodeIgniter.php';

    in your index.php

  • #27 / Dec 06, 2011 4:56pm

    Martin Dilling

    9 posts

    I thought i would just throw in the example that was in the zip when i downloaded DataMapper 1.8.2, and check out an working example to learn how to use it…. but… now I’ve tried for 3-4 hours to get it working -.-’ to find out what I’ve done wrong. Deleted everything, downloaded everything again, and copied it all ind again, many many many times. Looked through every single line in all config files, but i really can’t figure out what’s wrong -.-’

    It creates the databases right, and fills some data in it, and then…
    1. When I try to go forward, this shows up in the URL

    hxxp://localhost/codeigniter_testing/index.php/admin/<?= site_url(‘admin/init’) ?>

    annoying, but easy to jump to /admin/init.


    2. On the init site where i create a user, this shows up om top of the page:

    A PHP Error was encountered

    Severity: Warning

    Message: Invalid argument supplied for foreach()

    Filename: datamapper/htmlform.php

    Line Number: 52

    tried filling in the form anyways.


    3. Then I get a page only with this text:

    Fatal error: Uncaught exception ‘Exception’ with message ‘Unable to call the method “from_array” on the class User’ in C:\wamp\www\codeigniter_testing\application\libraries\datamapper.php:1277 Stack trace: #0 [internal function]: DataMapper->__call(‘from_array’, Array) #1 C:\wamp\www\codeigniter_testing\application\controllers\admin.php(166): User->from_array(Array, Array) #2 [internal function]: Admin->init(‘save’) #3 C:\wamp\www\codeigniter_testing\system\core\CodeIgniter.php(359): call_user_func_array(Array, Array) #4 C:\wamp\www\codeigniter_testing\index.php(203): require_once(‘C:\wamp\www\cod…’) #5 {main} thrown in C:\wamp\www\codeigniter_testing\application\libraries\datamapper.php on line 1277

     

    This is really really pissing me off xD I thought I was about to learn about the DataMapper, but ended up using 3-4 hours trying to get the example working, without luck -.-’ Really hope someone can help me xD

  • #28 / Dec 06, 2011 5:30pm

    Onema

    14 posts

    GREAT JOB WanWizard! I have been waiting for this update.

    I follow the install tutorial and it worked out of the box with no issues, and we have a decent size system.

    One question tho, I know CI 2.1 now has a PDO driver. Does ORM works with PDO? If that is the case, how? I tried just changing the driver to ‘pdo’. in the ci database.php config file.

    But I get this error message

    Uncaught exception ‘PDOException’ with message ‘invalid data source name’ in ...

     

  • #29 / Dec 06, 2011 6:50pm

    elmizan

    7 posts

    Then you haven’t read the docs, and didn’t install the bootstrap in your index.php file.

    This is new since 1.8.2, see http://datamapper.wanwizard.eu/pages/installation.html

    thank’s works for me. Just some advice, maybe you should update the offline documentation. :D

  • #30 / Dec 06, 2011 6:53pm

    elmizan

    7 posts

    Can I combine this plugin with ionAuth? I see the structure of database table seems same. any suggestion where I’m start

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

ExpressionEngine News!

#eecms, #events, #releases