<?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 relacjami]]></title>
	<link rel="self" href="http://forum.cakephp.org.pl/feed/atom/topic/77/"/>
	<updated>2009-07-07T20:35:23Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.cakephp.org.pl/topic/77/problem-z-relacjami/</id>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z relacjami]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/380/#p380"/>
			<content type="html"><![CDATA[<p>Tylko po cholere to dzielic na dwie tabele ....</p><div class="codebox"><pre><code>CREATE TABLE IF NOT EXISTS `cake_tmodule_galleries` (
  `id` int(10) NOT NULL auto_increment,
  `user_id` int(10) NOT NULL,
  `type` enum(&#039;album&#039;,&#039;image&#039;) NOT NULL default &#039;image&#039;,
  `parent_id` int(10) NOT NULL default &#039;0&#039;,
  `image_name` varchar(32) default NULL,
  `name` varchar(32) NOT NULL,
  `description` varchar(128) default NULL,
  `publish_from` varchar(10) default NULL,
  `publish_to` varchar(10) default NULL,
  `featured` tinyint(1) NOT NULL default &#039;0&#039;,
  `status` tinyint(1) NOT NULL default &#039;0&#039;,
  `allow_comment` tinyint(1) NOT NULL default &#039;0&#039;,
  `allow_rate` tinyint(1) NOT NULL default &#039;0&#039;,
  `sort` int(10) NOT NULL default &#039;0&#039;,
  `order_by` varchar(32) NOT NULL,
  `created` datetime default NULL,
  `modified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `deleted` tinyint(1) NOT NULL default &#039;0&#039;,
  `deleted_date` datetime default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=423 ;</code></pre></div><br /><p>teraz po koleji :<br />user_id - w mojej aplikacji mam jakies 3k usyztkownikow, kazdy moze miec swoja galerie, stad user_id<br />type - typ rekordu, album ( &quot;galeria&quot; moze zawierac inne &quot;pod-galerie&quot;), albo zdjecie <br />parent_id - id elementu rodzica<br />image_name - nazwa oryginalnie zuploadowanego obrazka ( u mnie wygenerowana losowo, kazdy obrazek ma domyslnie 3 rozmiary, thumbnail, image i featured , wyswietlajac zdjecie na stronie uzywam jednego z prefixow czylu np &quot;thumbnial_&quot; + image_name, gdy brak zdjecia dla alumu, album wyswietli losowo wbrany obrazek z posrod elementow ktore sie w nim zawieraja)<br />name - nazwa obrazka lub albumu<br />description - jak wyzej <br />publish_from, publish_to , daty poczaku i konca publikacji, uzywane jedynie przez cron&#039;a&nbsp; ktory co minute sprawdza dla ktorych rekordow ( nie tylko w galerii ) nalezy zaczac lub zakonczyc publikacje, i zmienia wtedy status z 1 na 0 lub 0 na 1<br />featured- wyroznianie odpowiedniego zdjecia , albumi itp , do roznych celi , np pokaznie na glowne stronie.<br />status , gdy = 0, rekord nie jest wybierany zadnym zapytaniem<br />allow_comment - zezlwala lub zabrania komentowania danego zdjecia przez uzytkownikow, ustawienie w przyapdku albumu powoduje dziedziczenie tego ustawienia dla wszytskich elementow w dol.<br />allow_rate - zelzwala lub zabrania oceniania danego zdjecia , reszta tak jak wyzej<br />sort - daje mozliwosc recznego przypisania kolenosci wyswietlania <br />order_by - sposob sortowania t po nazwie, dacie dodania, ilosci zdjec w labumie, ocenie , losowo&nbsp; lub po wartoscie pola sort itd ....<br />pola deleted* - pola behaviora SoftDeletable</p><p>dodatkowo mozliwosc uploadu wielu zdjec naraz ( przetwarzanie koleki cronem w tle i powiadomienie smsem po skonczeniu przetwarzania)</p><p>do wbierania rekordow zwykle uzywam find(&quot;all&quot;) albo find(&quot;threaded&quot;), prosto przyjemnie i latwo sie cache&#039;uje.</p>]]></content>
			<author>
				<name><![CDATA[robal77]]></name>
				<uri>http://forum.cakephp.org.pl/user/143/</uri>
			</author>
			<updated>2009-07-07T20:35:23Z</updated>
			<id>http://forum.cakephp.org.pl/post/380/#p380</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z relacjami]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/378/#p378"/>
			<content type="html"><![CDATA[<p>mam kolejny problem. podlacze sie pod ten temat poniewaz rowniez jest o relacjach.<br />mam dwa modele. Gallery oraz GalleryFile</p><div class="codebox"><pre><code>&lt;?php
class Gallery extends AppModel {

    var $name = &#039;Gallery&#039;;
    var $validate = array(
        &#039;name&#039; =&gt; array(&#039;notempty&#039;)
    );
    var $recuresive = 2;
    var $hasMany = array(
        &#039;GalleryFile&#039; =&gt; array(
            &#039;className&#039; =&gt; &#039;Galleryfile&#039;,
            &#039;foreignKey&#039; =&gt; &#039;galleries_id&#039;,
            &#039;dependent&#039;        =&gt; true,
            &#039;conditions&#039; =&gt; &#039;&#039;,
            &#039;fields&#039; =&gt; &#039;&#039;,
            &#039;order&#039; =&gt; &#039;&#039;
        )
    );

}
?&gt;</code></pre></div><div class="codebox"><pre><code>&lt;?php
class Galleryfile extends AppModel {

    var $name = &#039;Galleryfile&#039;;
    var $validate = array(
        &#039;galleries_id&#039; =&gt; array(&#039;numeric&#039;),
        &#039;filename&#039; =&gt; array(&#039;notempty&#039;),
        &#039;name&#039; =&gt; array(&#039;notempty&#039;)
    );

    //The Associations below have been created with all possible keys, those that are not needed can be removed
    var $belongsTo = array(
        &#039;Gallery&#039; =&gt; array(
            &#039;className&#039; =&gt; &#039;Galleries&#039;,
            &#039;foreignKey&#039; =&gt; &#039;galleries_id&#039;,
            &#039;conditions&#039; =&gt; &#039;&#039;,
            &#039;fields&#039; =&gt; &#039;&#039;,
            &#039;order&#039; =&gt; &#039;&#039;
        )
    );

}
?&gt;</code></pre></div><p>w kontrolerze Galleries w metodzie index chce miec liste galerii - oczywiscie to dziala<br /></p><div class="codebox"><pre><code>    function index() {
        $this-&gt;Gallery-&gt;recursive = 1;
        $this-&gt;set(&#039;galleries&#039;, $this-&gt;paginate());
        
        $this-&gt;pageTitle = __(&quot;pageTitle_home&quot; ,true) .__(&quot;Galleries&quot;,true);
    }</code></pre></div><p>tyle tylko, ze wczytuje mi od razu cala tablice z plikami. <br />potrzebuje tylko jeden rekord z tabeli GalleryFile w tej metodzie - zebym mogl wyciagnac miniature do galerii.<br />da sie to jakos zrobic?</p><p>pozdr.</p>]]></content>
			<author>
				<name><![CDATA[gaw]]></name>
				<uri>http://forum.cakephp.org.pl/user/95/</uri>
			</author>
			<updated>2009-07-07T08:54:28Z</updated>
			<id>http://forum.cakephp.org.pl/post/378/#p378</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z relacjami]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/376/#p376"/>
			<content type="html"><![CDATA[<div class="quotebox"><cite>duke_piotr napisał/a:</cite><blockquote><p>nazwy tabel sa w liczbie mnogiej a standardowo do klucza obcego dodajemy _id wiec na moje oko jest wlasnie OK.</p></blockquote></div><p>Moze i w przykladach tak jest lecz jednym z glownych nurtow nazewnictwa w RBD jeset wlasnie nazwa tabeli (l.m.) plus _id. </p><p>Z powodzeniem stosuje to w cake i nie ma problemu jak do tej pory (mialem jeden gdy tabela nazywala sie queues a w Cake nie szlo modelu nazwac Queue tylko tez Queues).</p>]]></content>
			<author>
				<name><![CDATA[duke_piotr]]></name>
				<uri>http://forum.cakephp.org.pl/user/31/</uri>
			</author>
			<updated>2009-07-07T08:39:23Z</updated>
			<id>http://forum.cakephp.org.pl/post/376/#p376</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z relacjami]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/374/#p374"/>
			<content type="html"><![CDATA[<div class="quotebox"><cite>duke_piotr napisał/a:</cite><blockquote><p>nazwy tabel sa w liczbie mnogiej a standardowo do klucza obcego dodajemy _id wiec na moje oko jest wlasnie OK.</p></blockquote></div><p>Dodajemy _id ale już do liczby pojedynczej czyli np. user_id, a nie users_id. Można to zobaczyc na przykładzie w dokumentacji przy relacjach : <a href="http://book.cakephp.org/view/80/hasOne">link</a></p>]]></content>
			<author>
				<name><![CDATA[rocichy]]></name>
				<uri>http://forum.cakephp.org.pl/user/222/</uri>
			</author>
			<updated>2009-07-06T13:24:34Z</updated>
			<id>http://forum.cakephp.org.pl/post/374/#p374</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z relacjami]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/369/#p369"/>
			<content type="html"><![CDATA[<p>nazwy tabel sa w liczbie mnogiej a standardowo do klucza obcego dodajemy _id wiec na moje oko jest wlasnie OK.</p>]]></content>
			<author>
				<name><![CDATA[duke_piotr]]></name>
				<uri>http://forum.cakephp.org.pl/user/31/</uri>
			</author>
			<updated>2009-07-06T08:43:38Z</updated>
			<id>http://forum.cakephp.org.pl/post/369/#p369</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z relacjami]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/362/#p362"/>
			<content type="html"><![CDATA[<p>Na moje oko blednie stworzyłeś nazwy pola bo powinno być &#039;product_id&#039; anie &#039;products_id&#039;. To co Bonetti podał to wsłanie naprawia ten bład.</p>]]></content>
			<author>
				<name><![CDATA[rocichy]]></name>
				<uri>http://forum.cakephp.org.pl/user/222/</uri>
			</author>
			<updated>2009-07-02T11:39:15Z</updated>
			<id>http://forum.cakephp.org.pl/post/362/#p362</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z relacjami]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/351/#p351"/>
			<content type="html"><![CDATA[<p>tak zrobiłem.</p><p>dodatkowo ustawilem recuresive na 2.<br />działa idealnie. dzieki!</p><p>pozdr.</p>]]></content>
			<author>
				<name><![CDATA[gaw]]></name>
				<uri>http://forum.cakephp.org.pl/user/95/</uri>
			</author>
			<updated>2009-06-12T09:29:14Z</updated>
			<id>http://forum.cakephp.org.pl/post/351/#p351</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z relacjami]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/350/#p350"/>
			<content type="html"><![CDATA[<p>Ja zrobił bym tak, że w modelu symbolu wpisał:</p><p>&nbsp; &nbsp; var $belongsTo = array(<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;Product&#039; =&gt; array(<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;className&#039; =&gt; &#039;Product&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;foreignKey&#039; =&gt; &#039;products_id&#039;<br />&nbsp; &nbsp; &nbsp; &nbsp; )<br />&nbsp; &nbsp; );</p><p>i w modelu Ingredient:</p><p>&nbsp; &nbsp; var $belongsTo = array(<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;Product&#039; =&gt; array(<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;className&#039; =&gt; &#039;Product&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;foreignKey&#039; =&gt; &#039;products_id&#039;<br />&nbsp; &nbsp; &nbsp; &nbsp; )<br />&nbsp; &nbsp; );</p><br /><p>Albo w modelu produktu:</p><p>&nbsp; &nbsp; var $hasMany = array(<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;Symbol&#039; =&gt; array(<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;className&#039; =&gt; &#039;Symbol&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;foreignKey&#039; =&gt; &#039;products_id&#039;<br />&nbsp; &nbsp; &nbsp; &nbsp; ),<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;Ingredient&#039; =&gt; array(<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;className&#039; =&gt; &#039;Ingredient&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;foreignKey&#039; =&gt; &#039;products_id&#039;<br />&nbsp; &nbsp; &nbsp; &nbsp; )<br />&nbsp; &nbsp; );</p><p>Mam nadzieje ze nie wprowadzam w błąd</p>]]></content>
			<author>
				<name><![CDATA[Bonetti]]></name>
				<uri>http://forum.cakephp.org.pl/user/41/</uri>
			</author>
			<updated>2009-06-12T09:25:16Z</updated>
			<id>http://forum.cakephp.org.pl/post/350/#p350</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Problem z relacjami]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/347/#p347"/>
			<content type="html"><![CDATA[<p>witam,</p><p>mam trzy tabele:<br />products<br />symbols<br />ingredients</p><p>chcialbym wszystkie 3 tabele polaczyc za pomoca products_id i wybierac dane za pomoca symbolu z tabeli symbols.</p><p>Produkt ma wiele symboli i wiele skladnikow (ingredients).<br />symbole i skladniki naleza do produktu.</p><p>tak wyglada model symobl<br /></p><div class="codebox"><pre><code>    var $belongsTo = array(
        &#039;Product&#039; =&gt; array(
            &#039;className&#039; =&gt; &#039;Product&#039;,
            &#039;foreignKey&#039; =&gt; &#039;id&#039;
        ),
        &#039;Ingredient&#039; =&gt; array(
        &#039;className&#039; =&gt; &#039;Ingredient&#039;,
        &#039;foreignKey&#039; =&gt; &#039;products_id&#039;
        )
    );</code></pre></div><p>Problem tego typu ze wybierajac http://localhost/symbols/views/ss-540 wybiera mi dane z bazy ze zlymi parametrami.<br /></p><div class="codebox"><pre><code>SELECT `Symbol`.`id`, `Symbol`.`products_id`, `Symbol`.`symbol`, `Product`.`id`, `Product`.`name`, `Product`.`dosage`, `Product`.`other_ingredients`, `Product`.`serving_size`, `Product`.`type`, `Product`.`date`, `Ingredient`.`id`, `Ingredient`.`product_id`, `Ingredient`.`name`, `Ingredient`.`quantity`, `Ingredient`.`rdz`, `Ingredient`.`order`, `Ingredient`.`proprietary_blend` FROM `sklady_symbols` AS `Symbol` LEFT JOIN `sklady_products` AS `Product` ON (`Symbol`.`id` = `Product`.`id`) LEFT JOIN `sklady_ingredients` AS `Ingredient` ON (`Symbol`.`products_id` = `Ingredient`.`id`) WHERE `Symbol`.`symbol` = &#039;PV-0139&#039; LIMIT 1</code></pre></div><p>Oczywiscie polaczenia sa zle, poniewaz `Symbol`.`id` = `Product`.`id`, a powinno byc `Symbol`.`products_id` = `Product`.`id` oraz zamiast `Symbol`.`products_id` = `Ingredient`.`products_id`.</p><p>byc moze powinien wybierac przez controller product ale nie umiem sie odwolac w tym cotrolerze do symbolu w innej tabeli.</p>]]></content>
			<author>
				<name><![CDATA[gaw]]></name>
				<uri>http://forum.cakephp.org.pl/user/95/</uri>
			</author>
			<updated>2009-06-12T08:25:03Z</updated>
			<id>http://forum.cakephp.org.pl/post/347/#p347</id>
		</entry>
</feed>
