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

[eluser]WanWizard[/eluser]
Can you do that with a standard $this->db call?

If so, you should be able to inject that in a DM query with a custom method, since DM uses CI's DB layer to construct its queries.

[eluser]BrainFeeder[/eluser]
Hello

We are working on this project where we are using dynamic databases for clients.
I made a basemodel where the db_params gets set in the constructor before parent::__construct() gets called.

All seemed to work just fine untill we had to use include_related(). Datamapper does not know where to look for the model table.

Is this a common problem or is there any solution for this? We are really stuck for the moment.

The code from basemodel:
Code:
function __construct($id = NULL)
{
parent::__construct($id);
}

function getParams($db) {
if ($db != NULL) {    
  // use these params as default
  $db_params = array_merge(array(
   'dbdriver'  => 'mysql',
   'pconnect'  => true,
   'db_debug'  => true,
   'cache_on'  => false,
   'char_set'  => 'utf8',
   'cachedir'  => '',
   'dbcollat'  => 'utf8_general_ci',
   'autoinit' => true,
   'stricton' => false,
   ), $db);
  return $db_params;
}
}

In all models that have the dynamic database we extend it from the above basemodel and in the constructor:

Code:
function __construct($id = NULL, $db = NULL)
{
$this->db_params = parent::getParams($db);
parent::__construct($id);
}

Now when I need some data from a dynamic database, I can do:
Code:
$con = new Config(NULL,$this->udb); // $this->udb is set on login and holds the database connection data
$con->get_iterated();

This works great, but when we try to include related tables and/or fields like this:
Code:
$con = new Config(NULL,$this->udb);
$con->include_related('status')->get_iterated();
// OR
// $con->include_related('status')->get();

Datamapper does not know which database to look for.

Maybe we need to set the db_params somewhere else ?

[eluser]nickaceph[/eluser]
Hi, Extending the DataMapper ORM for my Project is currently working well. nice ORM. Thanks

I got another questions, is it possible or is it already available on Datamapper ORM 1.8.2 multiple save, insert or update?

- I have a master detail purchase_order and a purchase_order_detail,
saving 1 item the purchase_order is easy? but is it possible that the ORM can receive an array in purchase_order_detail to save multiple rows? without looping each detail row?

Thanks

[eluser]davidMC1982[/eluser]
I'm either suffering a case of brain fade (most likely) or I've stumbled across an obscure problem.

Here's a snapshot my models:

Code:
class Order extends Datamapper {

var $has_many = array("orderdetail");

Code:
class Orderdetail extends Datamapper {

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

My tables are called "orders" and "orderdetails". My orderdetails table has the field order_id.

When attempting to do this:

Code:
if ($orderdetail->from_array($cart_content,'',TRUE))
{
//Save the relationship
$order->save($orderdetail);    
}

I get this error:

Code:
Unable to relate order with .

The order and the orderdetail gets saved to the database, but the relationship cannot be saved. This piece of code has been working faultlessly for over a year now. I've been making some modifications to the database and other areas of the code, but nothing that should effect this. Any clues?

Edit:

This does work however:
Code:
if ($orderdetail->from_array($cart_content,'',TRUE))
{
//Save the relationship
$orderdetail->save($order);    
}

[eluser]WanWizard[/eluser]
If $orderdetail is a new object, it should save it first.

The check is done on "id", so if $cart_content contains an "id", it might do something different? Did something change to what is in $cart_content ?

[eluser]davidMC1982[/eluser]
Hi,

Thanks for the response. Yes, the contents of $cart_contents has changed but it does not have an "id". I do this before I save and have confirmed that it works as expected:

Code:
unset($cart_contents['id']);

The $order is saved to the database, the $orderdetail is saved to the database in the call to from_array(). I've confirmed that both records exist, yet for some reason the association cannot be saved. Is the clue in the fact that Datamapper cannot identify what is being associated? That's what makes me think I'm missing something really obvious. It just seems strange that I'm having problems with such a simple relationship, despite this code working fine before. It's not like anything complex is happening.

[eluser]WanWizard[/eluser]
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...

[eluser]nickaceph[/eluser]
Hi, Thanks again,

I am now in-depth with my project dealing with data and I need to use get_iterated

but filtering it like so does not work:

$c = new Company();
$c->where('id', $id);
$c->limit(10, 20);
$c->get_iterated();


is there any other way or am I doing it wrong.

Thanks

[eluser]WanWizard[/eluser]
Looks like the code resets the select.

[eluser]nickaceph[/eluser]
I have tried adding option to the get_iterated() add reset, overriding it on my class and it does not reset from the code below but it still does not work. could you help me or is there any alternative?

public function get_iterated($reset = False, $limit = NULL, $offset = NULL)
{
// clone $this, so we keep track of instantiations, etc.
// because these are cleared after the call to get_raw
$object = $this->get_clone();

if( $reset ) {
// need to clear query from the clone
$object->db->dm_call_method('_reset_select');
// Clear the query related list from the clone
$object->_query_related = array();
}

// Build iterator
$this->_dm_dataset_iterator = new DM_DatasetIterator($object, $this->get_raw($limit, $offset, TRUE));
return $this;
}




Theme © iAndrew 2016 - Forum software by © MyBB