Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [cakephp] Problem z modelem
mr.r
post
Post #1





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 14.08.2006

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


Dopiero zaczynam swoją przygode z CakePHP, napotkałem na pewien problem podczas budowy modelu odpowiedzialnego za newsy.

Próbuje przerobić poniższe zapytanie:
  1. SELECT a.id,
  2. a.news_title,
  3. a.news_content,
  4. a.news_author,
  5. a.news_date,
  6. COUNT(b.id) AS news_comments_count,
  7. d.user_name
  8. FROM news a
  9. LEFT JOIN comments b ON b.comment_parent = a.id
  10. LEFT JOIN users d ON d.id = a.news_author
  11. GROUP BY a.id
  12. ORDER BY a.id DESC


na model bez większego powodzenia. Narazie tyle mam:
  1. <?php
  2. class News extends AppModel
  3. {
  4. var $name = 'News';
  5.  
  6. var $belongsTo = array('User' =>
  7.  array('className' => 'Users',
  8.  'conditions'  => '',
  9.  'order' => '',
  10.  'foreignKey'  => 'news_author',
  11.  'counterCache' => '' 
  12.  )
  13. );
  14.  var $hasAndBelongsToMany = array('Comms' =>
  15.  array('className' => 'Comments',
  16.  'joinTable' => 'comments',
  17.  'foreignKey' => 'comment_parent',
  18.  'associationForeignKey'=> 'id',
  19.  'conditions' => '',
  20.  'order' => '',
  21.  'limit' => '',
  22.  'uniq'  => true,
  23.  'finderSql' => '',
  24.  'deleteQuery'=> '',
  25.  )
  26. );
  27. }
  28. ?>


Pobiera co prawda newsy, autora i komentarze ale wykonuje przy tym 39 zapytań do bazy, czyli tyle ile jest newsów, jakby bylo ich 100 to pewnie by wykonało ~100 zapytań smile.gif
Liczenia ile komentarzy ma poszczególny news, nie udało mi sie zaimplementować do modelu.

Licze na pomoc... smile.gif

Ten post edytował mr.r 15.08.2006, 10:56:55
Go to the top of the page
+Quote Post

Posty w temacie


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: 19.08.2025 - 14:32