Hallo,
die aktuelle Query sieht so aus
und die Ausgabe sieht so aus
Das ganze macht das PostModell
Was ich genau will:
aus
soll
werden.
Ich will eigentlich nur die Kommentaranzahl ausgeben lassen und zwar in dem Array in dem die anderen Sachen auch stehen.
Alles anzeigen
Hoffe es ist ausführlich genug um mein Problem zu schildern.
gruß
EDIT://
Sowas wäre optimal =>
die aktuelle Query sieht so aus
Quellcode
- SELECT `Post`.`id`, `Post`.`title`, `Post`.`inhalt`, `Post`.`created`, `Post`.`modified`, `Post`.`category_id`, `Comment`.`id`, `Comment`.`comment`, `Comment`.`created`, `Comment`.`creator_id`, `Comment`.`modified`, `Comment`.`modifier_id`, `Comment`.`post_id`, `Category`.`id`, `Category`.`name` FROM `cake_posts` AS `Post` LEFT JOIN `cake_comments` AS `Comment` ON (`Post`.`id` = 'Comment.post_id') LEFT JOIN `cake_categories` AS `Category` ON (`Post`.`category_id` = `Category`.`id`) WHERE 1 = 1
und die Ausgabe sieht so aus
Quellcode
- id title inhalt created modified category_id id comment created creator_id modified modifier_id post_id id name
- 1 878 This is the post body. admin test 2011-09-26 12:20:35 2011-10-04 11:18:20 2 NULL NULL NULL NULL NULL NULL NULL 2 cat 2
- 2 Test12 Blubb this ondsf three23 tst 2011-09-26 12:20:35 2011-10-04 11:18:15 1 NULL NULL NULL NULL NULL NULL NULL 1 cat 1
- 3 123 3123123asd 2011-09-27 16:44:03 2011-10-04 11:18:09 1 NULL NULL NULL NULL NULL NULL NULL 1 cat 1
- 4 tst test 2011-09-28 18:13:50 2011-10-04 11:20:05 1 NULL NULL NULL NULL NULL NULL NULL 1 cat 1
- 5 esedt sdfsdf 2011-10-04 13:15:31 2011-10-04 13:15:31 1 NULL NULL NULL NULL NULL NULL NULL 1 cat 1
- 6 esedt sdfsdf 2011-10-04 13:17:03 2011-10-04 13:17:03 1 NULL NULL NULL NULL NULL NULL NULL 1 cat 1
- 7 esedt sdfsdf 2011-10-04 13:19:29 2011-10-04 13:19:29 1 NULL NULL NULL NULL NULL NULL NULL 1 cat 1
- 8 asdsad asdasd 2011-10-04 16:12:28 2011-10-04 16:12:28 1 NULL NULL NULL NULL NULL NULL NULL 1 cat 1
Das ganze macht das PostModell
Was ich genau will:
aus
LEFT JOIN `cake_comments` AS `Comment` ON (`Post`.`id` = 'Comment.post_id')
soll
LEFT JOIN `cake_comments` AS `Comment` ON (`Post`.`id` = `Comment`.`post_id'`)
werden.
Ich will eigentlich nur die Kommentaranzahl ausgeben lassen und zwar in dem Array in dem die anderen Sachen auch stehen.
Quellcode
- [0] => Array
- (
- [Post] => Array
- (
- [id] => 1
- [title] => 878
- [inhalt] => This is the post body. admin test
- [created] => 2011-09-26 12:20:35
- [modified] => 2011-10-04 11:18:20
- [category_id] => 2
- )
- [Comment] => Array
- (
- [id] =>
- [comment] =>
- [created] =>
- [creator_id] =>
- [modified] =>
- [modifier_id] =>
- [post_id] =>
- )
- [Category] => Array
- (
- [id] => 2
- [name] => cat 2
- )
- )
Hoffe es ist ausführlich genug um mein Problem zu schildern.
gruß
EDIT://
Sowas wäre optimal =>
Quellcode
- SELECT `Post`.`id` , `Post`.`title` , `Post`.`inhalt` , `Post`.`created` , `Post`.`modified` , `Post`.`category_id` , COUNT( `Comment`.`post_id` ) AS CommentCount, `Category`.`id` , `Category`.`name`
- FROM `cake_posts` AS `Post`
- LEFT JOIN `cake_comments` AS `Comment` ON ( `Post`.`id` = `Comment`.`post_id` )
- LEFT JOIN `cake_categories` AS `Category` ON ( `Post`.`category_id` = `Category`.`id` )
- WHERE `Post`.`id` =1