Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine objects are HUGE

Tags:

php

doctrine

I'm a .NET convert to PHP and am so far having a good time with the transition. I'm using doctrine 1.2 as my ORM and have my models working and everything is connected fine. However, the problem i'm looking at now is the output objects are enormous. I have a fairly simple table called USERS -- it has probably 8 columns and FKs to 4 or 5 other tables. I'm using the code below to hydrate my USERS object:

$q = Doctrine_Query::create()
->select('u.*')
->from('USERS u')
->where('u.VANITY_URL = ?',$Url_Frag);

$users = $q->execute();

print_r($users);

I see the object hydrated w/ my data so that's good. However, it also comes along with what looks like a bunch of meta data that I obviously don't need. Overall, the object is over 5000+ lines long! I'm sure there's an obvious switch somewhere that basically says "only emit such-and-such data" but I can't find it in the doctrine manual.

Thoughts?

like image 533
TJ Muehleman Avatar asked Sep 23 '11 20:09

TJ Muehleman


2 Answers

In Doctrine2, there is a dump() method available at:

\Doctrine\Common\Util\Debug::dump($var, $maxDepth)

It does a job similar to print_r and var_dump, but hides all the Doctrine-related data.

Maybe there is something similar for Doctrine 1.x?

like image 115
Artefact2 Avatar answered Nov 03 '22 15:11

Artefact2


Doctrine 1.2 entities object and collections has a method named "toArray". So you can do:

print_r($users->toArray());
like image 6
glerendegui Avatar answered Nov 03 '22 15:11

glerendegui