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

[eluser]NiconPhantom[/eluser]
[quote author="WanWizard" date="1329569892"]Datamapper actually uses CI's database classes, including "active record", to access the database.

So yes, everything CI does, Datamapper does too.[/quote]

Thank you WanWizard for the reply and specially for very great product!

Alex
#62

[eluser]toopay[/eluser]
"Active Record" term in CI, was misplaced terminology, dont you think WanWizard? I will call it "query builder", with extra object hydrator method.
#63

[eluser]WanWizard[/eluser]
Absolutely. I actually have that on one of my slides for CICONF in about an hour... Wink

We've proposed to Pascal Kriete last night to rename it to QB, but I think it was "lost in beer" somewhere...
#64

[eluser]NiconPhantom[/eluser]
Hi all,

I have yet another small question... I have hierarchical menu with relationship between id and parent_id, I have created model like that:

class menu_model extends DataMapper {


var $table = "menu";


var $has_one = array(

'parent' => array(
'class' => 'menu',
'other_field' => 'pid'
)
);

var $has_many = array(

'child' => array(
'class' => 'menu',
'other_field' => 'id'
)
);

function __construct()
{
parent::__construct();
}
}


and inside the controller:

$c1 = new menu_model();
$c1->get();

The problem is that print_r($c1,2) is returning not only DB content, but language translations and other staff as well, the data looks like few pages long array. Is it normal or I am doing something incorrectly?
#65

[eluser]WanWizard[/eluser]
Because Datamapper uses CI as much as possible, var_dump() and print_r() show a lot of information related to linked CI stuff, which is due to CI's architecture of hooking everything into $this. You don't have to worry about it, it's all by reference, so it doesn't take up (much) space. But it makes debugging more complex.

What I usually do is to load the 'array' extension (I actually do that by default), so you can do
Code:
// dump the current object
var_dump($c->to_array());
// dump all loaded objects
var_dump($c->all_to_array());
#66

[eluser]Maglok[/eluser]
I like that, it is a nice dump of the object. Is there an easy way to also dump all the objects that the current object has? Without needing to write a foreach for every one etc?

If a Person has_many Friends. This won't dump the friends.

Just wondering. Else I'll write something myself, cause this is indeed handy.
#67

[eluser]WanWizard[/eluser]
That is exactly what all_to_array() does.
#68

[eluser]Maglok[/eluser]
For that list of objects.

Example: 10 people are 10 instances of Person. It would show all 10 Person objects. But if each Person has an instance of a Pet class, it does not show those.
#69

[eluser]WanWizard[/eluser]
Currently to_array() and all_to_array() will add an array of id's when loaded relations are detected.

So if a Person would have a relation called 'pet', and there are 3 pets loaded, the array entry for that Person would contain 'pet' => array(1,5,12), assuming those are the id's of the loaded pets.

Not including them completely was done on purpose, to limit the size of the array.
#70

[eluser]Maglok[/eluser]
That makes sense. In this case I'd love to see them, so I am just writing a little function for it. Smile Keep up the good work.




Theme © iAndrew 2016 - Forum software by © MyBB