<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forum CakePHP.org.pl - Problem z $recursive]]></title>
	<link rel="self" href="http://forum.cakephp.org.pl/feed/atom/topic/18/"/>
	<updated>2008-10-10T09:58:16Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.cakephp.org.pl/topic/18/problem-z-recursive/</id>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z $recursive]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/43/#p43"/>
			<content type="html"><![CDATA[<div class="quotebox"><cite>duke_piotr napisał/a:</cite><blockquote><p>A to nie o to chodzilo w jego problemie?</p></blockquote></div><p>Nie, nie o to chodziło. Bazowałem ciągle na tym co mi zwracał SQL, ale okazało się że recursive jednak działa po podejrzeniu składni w debuggerze.<br />No a mój błąd był taki, że w widoku odnosiłem się do tego na czym mi zależało przez [&#039;Region&#039;][&#039;name&#039;], a prawidłowo powinno być [&#039;Town&#039;][&#039;Region&#039;][&#039;name&#039;].</p><p>W każdym bądź razie dzięki za pomoc - chociaż coś się na forum działo <img src="http://forum.cakephp.org.pl/img/smilies/wink.png" width="15" height="15" alt="wink" /></p>]]></content>
			<author>
				<name><![CDATA[Flo]]></name>
				<uri>http://forum.cakephp.org.pl/user/37/</uri>
			</author>
			<updated>2008-10-10T09:58:16Z</updated>
			<id>http://forum.cakephp.org.pl/post/43/#p43</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z $recursive]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/42/#p42"/>
			<content type="html"><![CDATA[<div class="quotebox"><cite>duke_piotr napisał/a:</cite><blockquote><p>A to nie o to chodzilo w jego problemie? Napisal ze ma jednego left joina i brakuje mu tylko drugiego. W ten sposob robiac findAll pobierze wszystkie Regiony i pasujace do nich Miasta i pasujace do nich Firmy.</p></blockquote></div><p>Wydaje mi się, że skoro jest w kontrolerze Corporation, to chce dla konkretnej korporacji pobrać dane na temat regionu i miasta. Zresztą nie o to się tutaj teraz rozchodzi, bo cokolwiek chce pobrać to i tak powinno to działać już w tej chwili (o ile wszystko jest rzeczywiście dobrze skonfigurowane).</p><div class="quotebox"><cite>duke_piotr napisał/a:</cite><blockquote><p>Jezeli zle zrozumialem problem to przepraszam <img src="http://forum.cakephp.org.pl/img/smilies/smile.png" width="15" height="15" alt="smile" /> Jezeli dobrze to wg. mnie brakuje szczegolowego opisu polaczenia baz miedzy Regionami i Firmami, jest jednokierunkowe, a model Miasta powinien laczyc ze soba obydwie tabele.</p></blockquote></div><p>Jeżeli chce pobrać dla danej firmy jej miasto i region, to nie potrzebuje więcej asocjacji niż ma w tej chwili, a ich dodanie tylko spowoduje potrzebę usuwania asocjacji &quot;w locie&quot;.</p><br /><p>Jeśli natomiast jest tak jak pisze duke_piotr, to wszystko tu jest źle <img src="http://forum.cakephp.org.pl/img/smilies/wink.png" width="15" height="15" alt="wink" /></p>]]></content>
			<author>
				<name><![CDATA[maciek]]></name>
				<uri>http://forum.cakephp.org.pl/user/6/</uri>
			</author>
			<updated>2008-09-29T09:55:07Z</updated>
			<id>http://forum.cakephp.org.pl/post/42/#p42</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z $recursive]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/41/#p41"/>
			<content type="html"><![CDATA[<div class="quotebox"><cite>maciek napisał/a:</cite><blockquote><p>$hasMany byłoby potrzebne gdyby chciał pobrać dla regionów wszystkie miasta, a dla miast wszystkie korporacje. Tak jak jest teraz - jest ok.<br />);</p></blockquote></div><p>A to nie o to chodzilo w jego problemie? Napisal ze ma jednego left joina i brakuje mu tylko drugiego. W ten sposob robiac findAll pobierze wszystkie Regiony i pasujace do nich Miasta i pasujace do nich Firmy.</p><p>Jezeli zle zrozumialem problem to przepraszam <img src="http://forum.cakephp.org.pl/img/smilies/smile.png" width="15" height="15" alt="smile" /> Jezeli dobrze to wg. mnie brakuje szczegolowego opisu polaczenia baz miedzy Regionami i Firmami, jest jednokierunkowe, a model Miasta powinien laczyc ze soba obydwie tabele.</p>]]></content>
			<author>
				<name><![CDATA[duke_piotr]]></name>
				<uri>http://forum.cakephp.org.pl/user/31/</uri>
			</author>
			<updated>2008-09-29T08:06:50Z</updated>
			<id>http://forum.cakephp.org.pl/post/41/#p41</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z $recursive]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/40/#p40"/>
			<content type="html"><![CDATA[<p>$this-&gt;Corporation-&gt;Town-&gt;Region-&gt;findAll();</p><p>daje</p><div class="codebox"><pre><code>SELECT `Region`.`id`, `Region`.`name` FROM `regions` AS `Region`</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Flo]]></name>
				<uri>http://forum.cakephp.org.pl/user/37/</uri>
			</author>
			<updated>2008-09-26T13:55:36Z</updated>
			<id>http://forum.cakephp.org.pl/post/40/#p40</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z $recursive]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/39/#p39"/>
			<content type="html"><![CDATA[<div class="quotebox"><cite>duke_piotr napisał/a:</cite><blockquote><p>Czesc,<br />Nie jestem za dobry w to ale nie powinno byc $hasMany ?</p></blockquote></div><p>$hasMany byłoby potrzebne gdyby chciał pobrać dla regionów wszystkie miasta, a dla miast wszystkie korporacje. Tak jak jest teraz - jest ok.</p><p>Flo, zapomnij o $query(). Tutaj na pewno to nie będzie potrzebne.</p><p>Spróbuj, zrobić $this-&gt;Corporation-&gt;Town-&gt;Region-&gt;findAll(); Jeśli pobierze Ci wszystkie regiony, to wtedy będzie to już zastanawiające...<br />Jeśli nie, to spróbuj zdefiniować zmienne $belongsTo w pełni, tzn.</p><br /><p>$belongsTo = array(<br />&nbsp; &nbsp; &#039;Town&#039; =&gt;array(<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;className&#039;=&gt;&#039;Town&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;foreignKey&#039;=&gt;&#039;town_id&#039;<br />&nbsp; &nbsp; )<br />);</p>]]></content>
			<author>
				<name><![CDATA[maciek]]></name>
				<uri>http://forum.cakephp.org.pl/user/6/</uri>
			</author>
			<updated>2008-09-26T12:56:35Z</updated>
			<id>http://forum.cakephp.org.pl/post/39/#p39</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z $recursive]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/38/#p38"/>
			<content type="html"><![CDATA[<p>Czesc,<br />Nie jestem za dobry w to ale nie powinno byc $hasMany ?</p>]]></content>
			<author>
				<name><![CDATA[duke_piotr]]></name>
				<uri>http://forum.cakephp.org.pl/user/31/</uri>
			</author>
			<updated>2008-09-26T11:52:40Z</updated>
			<id>http://forum.cakephp.org.pl/post/38/#p38</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z $recursive]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/37/#p37"/>
			<content type="html"><![CDATA[<p>Próbowałem już te kombinacje...</p><p>SQL zwraca</p><div class="codebox"><pre><code>SELECT `Corporation`.`id`, `Corporation`.`name`, `Corporation`.`town_id`, `Town`.`id`, `Town`.`name`, `Town`.`region_id` FROM `corporations` AS `Corporation` LEFT JOIN `towns` AS `Town` ON (`Corporation`.`town_id` = `Town`.`id`) WHERE 1 = 1 ORDER BY Corporation`.`name` DESC</code></pre></div><p>Ciągle brakuje LEFT JOIN&#039;a z tabelą regions...</p><p>No nic, będę musiał to załatwić długim, niechlujnym i niezgodnym z ideą programowania obiektowego $this-&gt;model-&gt;query()</p>]]></content>
			<author>
				<name><![CDATA[Flo]]></name>
				<uri>http://forum.cakephp.org.pl/user/37/</uri>
			</author>
			<updated>2008-09-26T11:35:37Z</updated>
			<id>http://forum.cakephp.org.pl/post/37/#p37</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z $recursive]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/36/#p36"/>
			<content type="html"><![CDATA[<p>Usuń z modelu $recursive = 2;</p><p>W kontrolerze tuż przed findAll() dodaj $this-&gt;recursive = 2;<br />Twoja funkcja findAll() powinna wyglądać tak : $this-&gt;Corporation-&gt;findAll(null,null, &#039;Corporation.name desc&#039;);</p><p>Ewentualnie możesz podać recursive również w findAll() : $this-&gt;Corporation-&gt;findAll(null,null, &#039;Corporation.name desc&#039;,null,null, 2);</p><p>Natomiast wg nowych standardów może to wyglądać jeszcze tak:<br />$this-&gt;Corporation-&gt;find(&#039;All&#039;, array(&#039;order&#039;=&gt;array(&#039;Corporation.name desc&#039;), &#039;recursive&#039;=&gt;2));</p>]]></content>
			<author>
				<name><![CDATA[maciek]]></name>
				<uri>http://forum.cakephp.org.pl/user/6/</uri>
			</author>
			<updated>2008-09-26T10:11:30Z</updated>
			<id>http://forum.cakephp.org.pl/post/36/#p36</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Problem z $recursive]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/35/#p35"/>
			<content type="html"><![CDATA[<p>Problem podobny do opisanego <a href="https://trac.cakephp.org/ticket/2931">tutaj</a>.<br />Mam 3 tabele corporations, towns, regions. Oczywiście w corporations jest kolumna town_id, no i w towns jest kolumna region_id.</p><p>Modele:</p><div class="codebox"><pre><code>class Corporation extends AppModel
{
    var $name=&#039;Corporation&#039;;
    var $belongsTo=&#039;Town&#039;;
}</code></pre></div><div class="codebox"><pre><code>class Town extends AppModel
{
    var $name=&#039;Town&#039;;
    var $belongsTo=&#039;Region&#039;;
}</code></pre></div><div class="codebox"><pre><code>class Region extends AppModel
{
    var $name=&#039;Region&#039;;
}</code></pre></div><p>I teraz wywołując w kontrolerze corporations_controller</p><div class="codebox"><pre><code>$this-&gt;set(&#039;corporation&#039;,$this-&gt;Corporation-&gt;findAll(&quot;ORDER BY Corporation.name ASC&quot;));</code></pre></div><p>chciałbym uzyskać też informację taką jak Region.name</p><p>Zmieniłem więc model corporations na</p><div class="codebox"><pre><code>class Corporation extends AppModel
{
    var $name=&#039;Corporation&#039;;
    var $recursive=2;
    var $belongsTo=&#039;Town&#039;;
}</code></pre></div><p>i nadal lipa ;( Tak jakby recursive w ogóle nie działało... Może trzeba gdzieś w konfigu coś zamieszać?</p><p>Mimo iż recursive jest ustawione na 2, SQL zwraca:</p><div class="codebox"><pre><code>SELECT `Corporation`.`id`, `Corporation`.`name`, `Corporation`.`town_id`, `Town`.`id`, `Town`.`name`, `Town`.`region_id` FROM `corporations` AS `Corporation` LEFT JOIN `towns` AS `Town` ON (`Corporation`.`town_id` = `Town`.`id`) ORDER BY `Corporation`.`name` ASC</code></pre></div><p>Czyli efekt jest taki sam jak wtedy gdy recursive jest ustawione na 0 lub na 1. Nie wiem, może coś robię źle, proszę o pomoc...</p>]]></content>
			<author>
				<name><![CDATA[Flo]]></name>
				<uri>http://forum.cakephp.org.pl/user/37/</uri>
			</author>
			<updated>2008-09-26T10:01:48Z</updated>
			<id>http://forum.cakephp.org.pl/post/35/#p35</id>
		</entry>
</feed>

