CodeIgniter Forums
DMZ 1.7.1 (DataMapper OverZealous Edition) - 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: DMZ 1.7.1 (DataMapper OverZealous Edition) (/showthread.php?tid=28550)



DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 09-29-2010

[eluser]matthewwithanm[/eluser]
@Lucas Yeah, The first echo (group_name) does work. The second (group->name) does not.

@WanWizard The final argument specifies whether to instantiate objects. http://www.overzealous.com/dmz/pages/getadvanced.html#include_related


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 09-29-2010

[eluser]WanWizard[/eluser]
I know the manual says it should work. But it doesn't. It's been reported serveral times in this thread.

I haven't gotten around to debug it...


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 09-29-2010

[eluser]WanWizard[/eluser]
It bugged me, so I went looking, and I think I found it.

The method _to_object() is responsible for creating objects out of query results. It requires the DMZ object and a row object as parameters. This works ok on the main query.

When it is done creating a DMZ object, it checks if there are instantiations of other objects that needs to be created (which is the case if you use an include_related with $instantiate = TRUE). It does that by creating an empty object for the related model (by calling _get_without_populating), and then copying the row retrieved in the related query to the new object by calling _to_object() again, this time with the related object and the retrieved row for that object.

This is the moment where it goes wrong. The row passed here is created just before that call, as an array, not as an object. Therefore, when _to_object is called, the "if (! isset($row->{$field}) " test fails, causing all object fields to be reset to NULL.

If you change the call so that the row is passed as an object, instantiation works properly:
Code:
// set the values, make sure $row is passed as an object
$c->_to_object($c, (object) $row);



DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 09-29-2010

[eluser]Dat Nguyen[/eluser]
Hi all, I am integrating the DMZ into CI 1.7.2. I am get following error, but I did not know how to resolve it, please help me:
Code:
Fatal error: Call to undefined method stdClass::_reset_select() in D:\xampplite\htdocs\asd\system\application\libraries\datamapper.php on line 1089

I already load the database in the application/config/autoload.php file:
Code:
$autoload['libraries'] = array('database', 'session', 'datamapper', 'lang_detect', 'language');

I got this error when I trying to create a simple example that inserts new record into a database table named "ci_users". I have a table prefix configuration in application/config/datamapper.php file as follow:
Code:
$config['prefix'] = 'ci_';

Here is my User model:
Code:
<?php
/*
* Created on Sep 30, 2010
*
* Filename: User.php
*/

class User extends DataMapper
{
    
    public function __construct()
    {
        parent::DataMapper();
        
        $this->validation = array(    
            'username' => array(
                'label' => lang('Username'),
                'rules' => array('required', 'trim', 'unique', 'alpha_dash', 'min_length' => 3, 'max_length' => 20),
            ),
            'first_name' => array(
                'label' => lang('First name'),
                'rules' => array('required', 'trim', 'max_length' => 30),
            ),
            'last_name' => array(
                'label' => lang('Last name'),
                'rules' => array('required', 'trim', 'max_length' => 30),
            ),
            'email' => array(
                'label' => lang('Email'),
                'rules' => array('required', 'trim', 'valid_email', 'max_length' => 100),
            ),
        );
    }
}
?>

And my controller:
Code:
<?php

class Welcome extends MY_Controller {

    function Welcome()
    {
        parent::MY_Controller();    
    }
    
    function index()
    {
        $user = new User();
        $user->username = 'datnguyen';
        $user->password = 'abc123';
        $user->email = '[email protected]';
        $user->first_name = 'Dat';
        $user->last_name = 'Nguyen';
        
        // Add user to database
        if ($user->save())
        {
            echo 'ID: ' . $user->id . '<br />';
        }
        else
        {
            foreach ($user->error->all as $error)
            {
                echo $error;
            }
        }
        
        $this->load->view('welcome_message');
    }
}

/* End of file welcome.php */
/* Location: ./modules/welcome/controllers/welcome.php */

I am using HMVC library (that published here) to separate my modules from CodeIgniter application folder.

Please let's me know what information I am missing to describe the error. Any suggestions are welcome!

Thanks and best regards, Dat.


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 09-30-2010

[eluser]Lucas Alves[/eluser]
@Dat Nguyen
Maybe this can help you:
http://ellislab.com/forums/viewthread/154350/


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 09-30-2010

[eluser]Dat Nguyen[/eluser]
[quote author="Lucas Alves" date="1285864583"]@Dat Nguyen
Maybe this can help you:
http://ellislab.com/forums/viewthread/154350/[/quote]

Thank you but it did not help to solve my problem. It's still there!


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 09-30-2010

[eluser]matthewwithanm[/eluser]
@Wan Thanks! I'll give it a try.


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 10-02-2010

[eluser]introvert[/eluser]
Hello.

I came to situation where I have to work with hierarchical data structures.
I thought of using nested sets approach instead of adjacency list.

Is there any info on how to easily implement it with DMZ? Has anyone already done that?

Would be cool to have model extension like:
http://codeigniter.com/wiki/Nested_sets/

Thanks for help.


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 10-02-2010

[eluser]Atas[/eluser]
Hello, i have discovered that datamapper skip SQL HAVING clause when i use get_paged(), i am trying to fix this...

Any Help Will be greatly appreciated!!


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 10-02-2010

[eluser]Lucas Alves[/eluser]
@introvert
I'd like to have this in DMZ too. I use this with a user hierarchical groups table. To do this, though, I just compiled some method from the mysql article into the group model, like add_group, change_group, remove_group...

But I'd like to have some more flexible, like the Nested Sets lib...