Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Kohana] relacje, ko3
nmts
post
Post #1





Grupa: Zarejestrowani
Postów: 283
Pomógł: 34
Dołączył: 21.03.2008

Ostrzeżenie: (0%)
-----


Chcę mieć relację pomiędzy użytkownikiem, a publikacją.

Użytkownik:
  1. class Model_User extends ORM {
  2.  
  3. protected $_has_many = array('publications' => array());
  4.  
  5. }


Publikacja:
  1. class Model_Publication extends ORM {
  2.  
  3. protected $_has_one = array('user' => array());
  4.  
  5. }


Wyświetlenie:
  1. publications = ORM::factory("publication")->find_all();
  2.  
  3. foreach($publications as $publication){
  4. $publication->content;
  5. // $publication->user->username
  6. }


Tabela brzmi publications i posiada user_id.
Jak powinno to wyglądać aby w foreach wyświetliło username autora publikacji?


--------------------
Free Web Tools - narzędzia dla programistów, webdeveloperów i specjalistów seo...
Go to the top of the page
+Quote Post
phpion
post
Post #2





Grupa: Moderatorzy
Postów: 6 072
Pomógł: 861
Dołączył: 10.12.2003
Skąd: Dąbrowa Górnicza




Chyba masz błąd w modelu publikacji: nie $_has_one tylko $_belongs_to.
Go to the top of the page
+Quote Post
Ormin
post
Post #3





Grupa: Zarejestrowani
Postów: 64
Pomógł: 0
Dołączył: 3.02.2009

Ostrzeżenie: (0%)
-----


Jeśli się nie myle to:
Kod
$publication->get_user()->username


?

Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 04:52