CodeIgniter Forums
DataMapper ORM v1.8.2 - 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 ORM v1.8.2 (/showthread.php?tid=47243)



DataMapper ORM v1.8.2 - El Forum - 04-27-2012

[eluser]WanWizard[/eluser]
Depends on what your old version is, and where you upgrade to.

Normally, you'll have to upgrade all Datamapper files (not only the library but also all extensions), and if you're using 1.8.2+, also the files in third_party/datamapper.


DataMapper ORM v1.8.2 - El Forum - 04-27-2012

[eluser]AlexMason[/eluser]
I got a join field:
Code:
users_groups
and have the model User and model Group but I'm not sure how to get the relating group field.. I tried to follow the docs but when I do this:
Code:
$user->group->where_join_field(...);

I get this error:
Code:
Fatal error: Call to undefined method Group::get_join_field() in C:\xampp\htdocs\application\controllers\file.php on line 31



DataMapper ORM v1.8.2 - El Forum - 04-27-2012

[eluser]ckm5[/eluser]
I've been using DMZ for a new website, successfully generating inserts, but I just ran into a problem while trying to update an existing table. I need some help figuring out if I'm doing something wrong.

The error is:

Code:
PHP Fatal error:  Call to undefined method CI_DB_mysql_driver::dm_call_method() in application/libraries/datamapper.php on line 3550

The actual call that generated this is:

Code:
// create customer - this works great
   $customer_attributes = new Customer();
   foreach($post['customer_attributes'] as $key => $value) {
    $customer_attributes -> $key = $value;
   }
   $customer_attributes -> save();

// [some stuff happens here - remote API calls + cleanup of results]

// now update customer with data from API - broken, error in log
$customer_attributes->where('uuid =',$post['customer_attributes']['uuid'])->update('customer_id',$customer_data['id']);

All the table columns are valid, all the variables have values. I'm running DMZ 1.8.2 (which I just updated from 1.8 because of a bug with multiple DBs - which I use, set in datamapper config) and CI 2.1 on PHP 5.3.2 on Ubuntu 10.04.1 LTS.

And, before you ask, yes DMZ is bootstrapped in index.php - I RtFM'd. And DMZ seems to work for inserts, I've been doing that for a week, just not for updates....

Thx.

Chris.


DataMapper ORM v1.8.2 - El Forum - 04-27-2012

[eluser]AlexMason[/eluser]
Are you extending the datamapper in the model class?


DataMapper ORM v1.8.2 - El Forum - 04-27-2012

[eluser]ckm5[/eluser]
[quote author="AlexMason" date="1335585734"]Are you extending the datamapper in the model class?[/quote]

Yup. Works fine on inserts....

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Customer extends DataMapper {

// rather specify a table as it makes things clearer for maintenance
var $table = 'customer';

    // Optionally, don't include a constructor if you don't need one.
    function __construct($id = NULL)
    {
        parent::__construct($id);
    }

    // Optionally, you can add post model initialisation code
    function post_model_init($from_cache = FALSE)
    {
    }
}

/* End of file customer.php */
/* Location: ./application/models/customer.php */
?>



DataMapper ORM v1.8.2 - El Forum - 04-28-2012

[eluser]WanWizard[/eluser]
@AlexMason,

I need to se the exact statement to see where the join field query goes wrong. there is no get_join_field(), so the error in itself is correct.


DataMapper ORM v1.8.2 - El Forum - 04-28-2012

[eluser]WanWizard[/eluser]
@ckm5,

If you get that error then $this->db doesn't point to Datamapper but to the original CI class.

As line 3550 in my version doesn't contain a dm_call_method() call, I suggest you upgrade to the latest version first (both library, extensions and the third_party/datamapper folder) from bitbucket.


DataMapper ORM v1.8.2 - El Forum - 04-28-2012

[eluser]AlexMason[/eluser]
[quote author="WanWizard" date="1335605923"]@AlexMason,

I need to se the exact statement to see where the join field query goes wrong. there is no get_join_field(), so the error in itself is correct.[/quote]

It happens when I use where join field also:
Code:
public function upload() {
            $data['title'] = "Upload";
            $uid = $this->ion_auth->user()->row()->id;
            $user = new User($uid);
            $user->group->where_join_field($user)->get();
            //$per = new Permission();
            //$group_id = $user->group->group_id;
            if ($uid != false) {
                echo print_r($uid);
            } else {
                echo 'No User Found!';
            }
            
            $this->parser->parse('header', $data);
            $this->parser->parse('file/upload', $data);
            $this->parser->parse('footer', $data);
        }
Error:
Code:
Fatal error: Call to undefined method Group::where_join_field() in C:\xampp\htdocs\application\controllers\file.php on line 31



DataMapper ORM v1.8.2 - El Forum - 04-28-2012

[eluser]WanWizard[/eluser]
There's something seriously wrong with your setup.

Datamapper contains a __call() magic method that will capture all calls to unknown methods, and will determine which internal methods to call. In case of where_include_field(), Datamapper will split it into a where() and a include_field() call.

If __call() isn't able to map the method, it will fail with an "Unable to call the method $method on the class" exception, and not a PHP fatal error.

Your User and Group models both extend Datamapper? You don't have other classes called User or Group? Do a var_dump($user) and var_dump($user->group) to make sure.

and p.s.: where_join_field() requires three arguments, not only the object of the join.


DataMapper ORM v1.8.2 - El Forum - 04-28-2012

[eluser]AlexMason[/eluser]
Quote:Ok fixed that problem I wasn't extending datamapper in group, now the second problem arises.

I got the databases:
users - user info is here
users_groups - relationships here
groups - groups here

How would I get the group id based on the user using datamapper. It just returns a 1 and the group id is 2 here is the code I am using now:
Code:
$user = new User($uid);
            $group = $user->group->id;

users_groups structure:
[Image: oN6Hu.png]
Figured out the problem on my own. First you need to make sure your relationship database is in order by name so groups before users. Then always remember your ->get() here is the working code I have:
Code:
$uid = $this->ion_auth->user()->row()->id;
            $user = new User($uid);
            $group = $user->group->get();
            if ($uid != false) {
                echo $group->id.'<br />'.$group->name.'<br />'.$group->description;
            } else {
                echo 'No User Found!';
            }
Hope this helps anyone.