<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forum CakePHP.org.pl - habtm]]></title>
	<link rel="self" href="http://forum.cakephp.org.pl/feed/atom/topic/78/"/>
	<updated>2009-07-06T12:54:01Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.cakephp.org.pl/topic/78/habtm/</id>
		<entry>
			<title type="html"><![CDATA[Odp: habtm]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/373/#p373"/>
			<content type="html"><![CDATA[<p>Zalezy czy dodasz do definicji pola<br />ON UPDATE CURRENT_TIMESTAMP<br />czy nie</p>]]></content>
			<author>
				<name><![CDATA[duke_piotr]]></name>
				<uri>http://forum.cakephp.org.pl/user/31/</uri>
			</author>
			<updated>2009-07-06T12:54:01Z</updated>
			<id>http://forum.cakephp.org.pl/post/373/#p373</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: habtm]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/371/#p371"/>
			<content type="html"><![CDATA[<p>Witam</p><p>id02009 - probowalem tak jak napisales na rozne sposoby, niestety nie dziala, cake operuje tylko na worker_id i workplace_id - dodanie recznie danych nic nie daje <img src="http://forum.cakephp.org.pl/img/smilies/hmm.png" width="15" height="15" alt="hmm" /> imo tak to powinno wygladac</p><p>carlin - zrobilem. Dziala, jest tylko blad przy odczycie, ale zapis poprawny. W koncu zrobilem tak, ze ustawilem habtm i sposob alfabeta na raz <img src="http://forum.cakephp.org.pl/img/smilies/tongue.png" width="15" height="15" alt="tongue" /> odczyt realizuje przez habtm, zapis - sposob alfabeta <img src="http://forum.cakephp.org.pl/img/smilies/big_smile.png" width="15" height="15" alt="big_smile" /> troszke nie poprawnie z punktu widzenia modelowania bd ale dziala. Co prawda tablica zwracana przez sql jest ekhm... duza, ale to tylko kwestia ustawienia paginacji, by nie bylo ogromnych transferow danych w jednym czasie.</p><p>duke_piotr - w sumie nie pomyslalem. Wygodnie jakby baza zalatwila to za cake, tylko nie wiem jak to sie bedzie mialo do polecenia UPDATE czy w kolumnie data, zostanie wstawiona aktualna wartosc czy zostanie ta stara - chodzi tu o poprawienie stanowiska w sytuacji gdy uzytkownik wprowadzajacy pracownika sie pomyli i bedzie chcial mu poprawic stanowisko (a nie zmienic na nowe, obowiazujace od danej daty) - przetestuje to i dam znac jak wyszlo</p><p>Dziekuje wszystkim za pomoc i ide walczyc dalej <img src="http://forum.cakephp.org.pl/img/smilies/big_smile.png" width="15" height="15" alt="big_smile" /></p>]]></content>
			<author>
				<name><![CDATA[dredd]]></name>
				<uri>http://forum.cakephp.org.pl/user/223/</uri>
			</author>
			<updated>2009-07-06T09:15:12Z</updated>
			<id>http://forum.cakephp.org.pl/post/371/#p371</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: habtm]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/368/#p368"/>
			<content type="html"><![CDATA[<p>@dredd -&gt; a z poziomu SQl nowa kolumna TIMESTAMP nie wystarczy? Nie musisz nic uzupełniac tylko odczytujesz date.</p>]]></content>
			<author>
				<name><![CDATA[duke_piotr]]></name>
				<uri>http://forum.cakephp.org.pl/user/31/</uri>
			</author>
			<updated>2009-07-06T08:41:57Z</updated>
			<id>http://forum.cakephp.org.pl/post/368/#p368</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: habtm]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/367/#p367"/>
			<content type="html"><![CDATA[<p>A może spróbować w tym modelu WorkersWorkplace dodać funkcje <a href="http://book.cakephp.org/view/683/beforeSave">beforeSave</a> i jakoś wypełnić te pole. Nigdy nie próbowałem ale może ...</p>]]></content>
			<author>
				<name><![CDATA[rocichy]]></name>
				<uri>http://forum.cakephp.org.pl/user/222/</uri>
			</author>
			<updated>2009-07-06T06:57:45Z</updated>
			<id>http://forum.cakephp.org.pl/post/367/#p367</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: habtm]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/366/#p366"/>
			<content type="html"><![CDATA[<p>Cake przy habtm tworzy automagicznie model WorkersWorkplace, więc możesz spróbować zrobić to w taki sposób:<br />$this-&gt;data[&#039;WorkersWorkplace&#039;][&#039;dodatkowa_kolumna&#039;] = &#039;tysioncpińcset&#039;;<br />$this-&gt;Worker-&gt;save($this-&gt;data); //albo saveAll();</p><p>daj znać, czy działa.</p>]]></content>
			<author>
				<name><![CDATA[id02009]]></name>
				<uri>http://forum.cakephp.org.pl/user/199/</uri>
			</author>
			<updated>2009-07-04T20:31:54Z</updated>
			<id>http://forum.cakephp.org.pl/post/366/#p366</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: habtm]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/365/#p365"/>
			<content type="html"><![CDATA[<p>hej. Dokładnie tak jak napisałeś. Z habtm są problemy i chyba najłatwiej jest to zrobić ręcznie ustawiając tabelę łączącą tak jak napisałeś. Bynajmniej ja tak zrobiłem i mogę dodawać dowolną ilość dodatkowych pól.</p>]]></content>
			<author>
				<name><![CDATA[carlin]]></name>
				<uri>http://forum.cakephp.org.pl/user/170/</uri>
			</author>
			<updated>2009-07-04T14:11:08Z</updated>
			<id>http://forum.cakephp.org.pl/post/365/#p365</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: habtm]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/364/#p364"/>
			<content type="html"><![CDATA[<p>Witam mam podobny problem. Mam zrobic historie zatrudnienia, dwie tabelki <strong>workers</strong> i <strong>workplaces</strong>, tabela laczaca <strong>workers_workplaces</strong> i przy habtm odczyt danych jest bez problemu, jednakze tabelka przejsciowa musi miec dodatkowa kolumne data, by pamietac kiedy dane stanowisko zostalo zmienione. Przy zapisywaniu nie jest ona wypelniania mimo ze w $this-&gt;data ustawiam dodatkowa kolumne.</p><p>Wiem ze rozwiazanie jest powyzej, ale cos nie moge skumac - generalnie olac habtm i zrobic recznie tak jak zaporponowal alfabeta?<br />Czyli stworzyc dowolna tabele (model - wg standardow cakephp - workers_workplaces) i workers dac hasMany workers_workplaces, w workers_workplaces belongsTo worker i belongsTo workplaces?</p>]]></content>
			<author>
				<name><![CDATA[dredd]]></name>
				<uri>http://forum.cakephp.org.pl/user/223/</uri>
			</author>
			<updated>2009-07-03T09:10:47Z</updated>
			<id>http://forum.cakephp.org.pl/post/364/#p364</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: habtm]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/359/#p359"/>
			<content type="html"><![CDATA[<p>Dzięki, problem rozwiązany.</p>]]></content>
			<author>
				<name><![CDATA[carlin]]></name>
				<uri>http://forum.cakephp.org.pl/user/170/</uri>
			</author>
			<updated>2009-06-27T16:28:02Z</updated>
			<id>http://forum.cakephp.org.pl/post/359/#p359</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: habtm]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/353/#p353"/>
			<content type="html"><![CDATA[<p>1.<br />Do tabeli pośredniej orders_products dołącz dodatkową kolumnę. <br />Ja miałem problemy z działaniem związków HABTM po takim manewrze więc napisałem własny bahavior dla tego modelu.<br />Z tego co pamiętam udało mi się działać z jedną kolumną dodatkową ale przy 2 już były problemy.</p><p>albo prościej</p><p>2.<br />Do modelu Orders dodać hasMany Details. W modelu Details zrobić belongsTo Order. Można też dodać belongsTo Product.<br />W tym modelu trzymać szczegóły zamówienia tj.</p><p>order_id INT UNSIGNED NOT NULL<br />product_id INT UNSIGNED <br />ile_sztuk INT UNSIGNED<br />.....<br />itd. itp.</p>]]></content>
			<author>
				<name><![CDATA[alfabeta]]></name>
				<uri>http://forum.cakephp.org.pl/user/140/</uri>
			</author>
			<updated>2009-06-22T08:02:02Z</updated>
			<id>http://forum.cakephp.org.pl/post/353/#p353</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[habtm]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/352/#p352"/>
			<content type="html"><![CDATA[<p>Witam,</p><p>Mam następujący problem. Posiadam dwie tabele: Orders, Products, ponieważ potrzebuje do jednego zamówienia przypisać wiele produktów skorzystałem z habtm i stworzyłem tabele łączącą orders_products. Model Order i Product&nbsp; korzystają z &#039;extendAssociations&#039;:</p><p>var $actsAs&nbsp; &nbsp;= array(&#039;extendAssociations&#039;);</p><p>oraz posiadają relację &#039;hasAndBelongsToMany&#039;.</p><br /><p>W kontrolerze orders_controller mam funkcję dodającą zamówienie:</p><p>function addOrd() {<br />&nbsp; &nbsp; &nbsp; &nbsp; $this-&gt;set(&#039;products&#039;, $this-&gt;Order-&gt;Product-&gt;find(&#039;list&#039;, array(&#039;fields&#039; =&gt; array(&#039;Product.id&#039;, &#039;Product.Nazwa&#039;))));<br />&nbsp; &nbsp; &nbsp; &nbsp; $this-&gt;set(compact(&#039;products&#039;));</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if (!empty($this-&gt;data)) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( $this-&gt;Order-&gt;saveAll($this-&gt;data)) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $this-&gt;redirect(&#039;/&#039;);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; }</p><p>W odpowiadającym tej funkcji widoku mam taką formułę:</p><br /><p>echo $form-&gt;input( &#039;Product.Product&#039;, <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; array( &#039;type&#039;=&gt;&#039;select&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;multiple&#039;=&gt;&#039;true&#039;,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#039;options&#039;=&gt;$products,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;label&#039;=&gt;&#039;Produkty:&#039;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )<br />&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; );</p><p>Dodaje zamówienie i zaznaczam z ctrl kolejne produkty. Działa poprawnie. Chciałbym jednak dodatkowo do każdego zaznaczonego produktu dodawać ilość sztuk czyli żeby do kazdego rekordu w orders_products dodawać pole &#039;Sztuki&#039;. Jeśli ktoś wie jak to można zrealizować to będę wdzięczny. Dziękuje z góry.</p><p>Pozdrawiam.</p>]]></content>
			<author>
				<name><![CDATA[carlin]]></name>
				<uri>http://forum.cakephp.org.pl/user/170/</uri>
			</author>
			<updated>2009-06-17T21:36:18Z</updated>
			<id>http://forum.cakephp.org.pl/post/352/#p352</id>
		</entry>
</feed>

