Welcome Guest, Not a member yet? Register   Sign In
DataMapper ORM v1.8.2

[eluser]WanWizard[/eluser]
Looked at it again.

The reset should be there, as an empty object must be passed to the iterator. The query is run by $this->get_raw(), which is on the current object.

get_raw() does nothing more then run a standard $this->db->get(), so I don't see why the where clause would not be honored in your example. It will ignore the limit() call, since you need to pass offset and limit to get_iterated(), and if you don't, the default NULL values will reset your previous setting.

[eluser]nickaceph[/eluser]
Thanks,
Got it. run through the code again and got what i needed.

$model->where('id',2)->limit(1,0);

$qq = $model->get_raw();

$ww= $qq->result_array();

that's it, I will just need to encapsulate it in the inherited class

thanks

[eluser]davidMC1982[/eluser]
[quote author="WanWizard" date="1378116496"]I find it odd that the error message is missing the related object name ("unable to relate order with <missing>."), which can only happen if it can't find the "model" property.

Which fields are exactly in $cart_contents? Any field that might overwrite a reserved model object property, such as "model"?

p.s. I don't support Datamapper anymore, so I really don't have time to dive into it if this is not the problem...[/quote]

Hi,

The same error is now happening with another relationship, where the save should be for an "empty" object.

Code:
//Displays a test report
function test_report($orderdetail_id) {
  
  $orderdetail = new Orderdetail($orderdetail_id);
  
  $orderdetail->test_report->get();
  
  //If the test report doesn't exist, create a new one and save to the orderdetail
  if (!$orderdetail->test_report->exists()) {
   $test_report = new Test_report();
   $test_report->save($orderdetail);
  }
  
  $data['orderdetail'] = $orderdetail;
    
  //Load the views
  $this->load->view('admin/header');
  $this->load->view('admin/test_report');
  $this->load->view('admin/footer');    
  
}

Code:
&lt;?php
class Orderdetail extends Datamapper {

var $has_one = array("order", "item", "test_report");

    function __construct($id = NULL)
    {
        parent::__construct($id);
    }
}

Code:
&lt;?php
class Test_report extends Datamapper {

var $has_one = array("orderdetail");

    function __construct($id = NULL)
    {
        parent::__construct($id);
    }
}

This time it's for a one-to-one relationship but it's using the same model. The only potential clue is that in both cases it's the $some_model->save($orderdetail) that doesn't work. Saving the relationship using $orderdetail->save($some_model) does work.

I know you don't have time to debug etc, but do you have any ideas where to look?

Thanks

[eluser]WanWizard[/eluser]
You've got the latest version from Bitbucket? I vaguely remember some fixes in this area.

[eluser]davidMC1982[/eluser]
Funnily enough, I remember not having the latest version was the cause of a previous problem ( to_json() bugs ) so I "updated" to the latest version per your website, 1.8.2.1. This seems to be almost two years out-of-date per bitbucket so I'll just download the latest commit and try that.

Many thanks for your help.

[eluser]WanWizard[/eluser]
Haven't been really active with CI since 2011, so that is quite possible.

I tried to keep the code on bitbucket up to date, but didn't have time to do anything else (like releasing or documentation).

[eluser]NotSmilie[/eluser]
Hi,

This is really great, amazing library you have created here!

I do have some issues, which I'm not sure how to go on about.

My error is this one:
http://i.imgur.com/o80sBTA.png

My code is as follows:

Code:
&lt;?php
/**
* Created by JetBrains PhpStorm.
* User: Mikkel
* Date: 12-10-13
* Time: 22:17
* To change this template use File | Settings | File Templates.
*/

class User extends DataMapper {

    var $table = 'users';

    var $auto_populate_has_many = TRUE;
    var $auto_populate_has_one = TRUE;
    var $has_many = array(
                    'privileges' => array(   // in the code, we will refer to this relation by using the object name 'book'
                        'class' => 'prvilege',   // This relationship is with the model class 'book'
                        'other_field' => 'user',  // in the Book model, this defines the array key used to identify this relationship
                        'join_self_as' => 'user',  // foreign key in the (relationship)table identifying this models table. The column name would be 'author_id'
                        'join_other_as' => 'privilege',  // foreign key in the (relationship)table identifying the other models table as defined by 'class'. The column name would be 'book_id'
                        'join_table' => 'user_priv_relations'), // name of the join table that will link both Author and Book together
                    'usergroups' => array(   // in the code, we will refer to this relation by using the object name 'book'
                        'class' => 'usergroup',   // This relationship is with the model class 'book'
                        'other_field' => 'user',  // in the Book model, this defines the array key used to identify this relationship
                        'join_self_as' => 'user',  // foreign key in the (relationship)table identifying this models table. The column name would be 'author_id'
                        'join_other_as' => 'usergroup',  // foreign key in the (relationship)table identifying the other models table as defined by 'class'. The column name would be 'book_id'
                        'join_table' => 'user_group_relations'), // name of the join table that will link both Author and Book together
                    );

    // 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)
    {
    }
}

My database tables can be seen on the left side on this image:
http://i.imgur.com/qaoZjWR.png

I tried to use mysql instead of mysqli without any change in the error message (except that it was mysql instead of mysqli).

I tried comment out auto populate, and the has many relations, without luck as well.
The error occurs when I try to simply get a user by:
$user = new User();
$user->where("id", $primary_key)->get();

[eluser]kakallatt[/eluser]
I don't understand why it return INSERT query. It should be UPDATE.

My table is using slug for primary key instead of id. Does it cause??

Here is my code:

Code:
public function set_item($slug, $value) {
  if (is_string($slug)) {;
   $this->get_by_slug($slug);
   $this->value = $value;

   if ($this->save()) {
    return TRUE;
   }
  }

  return FALSE;
}

Thank you.

[eluser]Unknown[/eluser]
Wanted to add my thanks for Bard's hack on pg.35. As much as I hate having to mess with the actual active record code, it's beyond frustrating that it prevents us from accomplishing what we need to do.

[eluser]chiqui3d[/eluser]
How I can get model name in the controller?

I'm trying to self ::$model;.

Code:
Access to undeclared static property: miclass::$model in

Any help?

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB