[TYPO3-mvc] @lazy in model does not bring the expected results... why?

Manfred Rutschmann manfred.rutschmann at revier.de
Thu Jul 14 11:21:43 CEST 2011


Hi list,

official t3 4.5.3.

I have a model with a 1:1 relation to the same table. The field for this is
"category".

In my model ist this defined:

---snip---

	/**
	 * Parent Category
	 *
	 * @var Tx_Mrad_Domain_Model_Category
	 * @lazy
	 */
	protected $category;

	/**
	 * @param Tx_Mrad_Domain_Model_Category $category
	 * @return void
	 */
	public function setCategory(Tx_Mrad_Domain_Model_Category $category) {
		if ($this->category instanceof Tx_Extbase_Persistence_LazyLoadingProxy) {
			$this->category->_loadRealInstance();
		}
		return $this->category;			
	}

	/**
	 * @return Tx_Mrad_Domain_Model_Category
	 */
	public function getCategory() {
		return $this->category;
	}


---snip---

in my logic method i build a array with the levels and names (only for test
at the moment):

--- snip ---
/**
 * Get an array back with all levels of categories (array with objects)
 * 
 * return array
 */
public function getCategoryArray()
{
	$refs = array();
	$list = array();
	$entries = $this->categoryRepository->findAll()->toArray();

	if(is_array($entries))
	{
		foreach ($entries as $obj) 
		{
			
			$thisref = &$refs[ $obj->getUid() ];

			if($obj->getCategory() instanceof Tx_Mrad_Domain_Model_Category)
			$thisref['parent'] = $obj->getCategory()->getUid();

			$thisref['title'] = $obj->getTitle();
			
			if(!$obj->getCategory() instanceof Tx_Mrad_Domain_Model_Category)
			{
		        $list[ $obj->getUid() ] = &$thisref;
		    	} else {
		        $	refs[ $obj->getCategory()->getUid()  ]['children'][
$obj->getUid() ] = &$thisref;
		    	}
		}
	}
	t3lib_div::debug($refs);
}

--- snip ---

With @lazy in annotation i get these output:

Array
(
    [2] => Array
        (
            [title] => Fahrzeugmarkt
        )
 
    [3] => Array
        (
            [title] => Immobilien
        )
---snip--- 
)

without the lazy, i get this:



Array
(
    [2] => Array
        (
            [parent] => 7
            [title] => Fahrzeugmarkt
            [children] => Array
                (
                    [8] => Array
                        (
                            [parent] => 2
                            [title] => Alfa-Romeo
                        )
 
                    [9] => Array
                        (
                            [parent] => 2
                            [title] => Audi
                        )
 
                    [10] => Array
                        (
                            [parent] => 2
                            [title] => Austin
                        )
 
                    [11] => Array
                        (
                            [parent] => 2
                            [title] => Autobianchi
                        )
 
                    [12] => Array
                        (
                            [parent] => 2
                            [title] => BMW
                        )
 
                )
 
        )
 
    [7] => Array
        (
            [children] => Array
                (
                    [2] => Array
                        (
                            [parent] => 7
                            [title] => Fahrzeugmarkt
                            [children] => Array
                                (
                                    [8] => Array
                                        (
                                            [parent] => 2
                                            [title] => Alfa-Romeo
                                        )
 
                                    [9] => Array
                                        (
                                            [parent] => 2
                                            [title] => Audi
                                        )
 
                                    [10] => Array
                                        (
                                            [parent] => 2
                                            [title] => Austin
                                        )
 
                                    [11] => Array
                                        (
                                            [parent] => 2
                                            [title] => Autobianchi
                                        )
 
                                    [12] => Array
                                        (
                                            [parent] => 2
                                            [title] => BMW
                                        )
 
                                )
 
                        )
 
                    [13] => Array
                        (
                            [parent] => 7
                            [title] => Autovermietungen
                        )
 
                    [14] => Array
                        (
                            [parent] => 7
                            [title] => Garagen
                        )
 
                    [15] => Array
                        (
                            [parent] => 7
                            [title] => Wohnwagen / Wohnmobile
                        )
 
                )
 
            [title] => KFZ-Markt
        )
 
    [3] => Array
        (
            [title] => Immobilien
        )

--- snip ---

But why? @lazy loads the data when i need this. And $obj->getCat->getProp
requests the linked object, or not?!?

Regards Manfred


More information about the TYPO3-project-typo3v4mvc mailing list