2011-08-07 81 views
0
Tag: 
    columns: 
    name:    
     type: string(100) 

TagNews: 
    columns: 
    tag_id: 
     type: integer 
     primary: true 
    news_id: 
     type: integer 
     primary: true 
    relations: 
    Tag:  { onDelete: CASCADE, local: tag_id, foreign: id } 
    News:  { onDelete: CASCADE, local: news_id, foreign: id } 

News: 
    columns: 
    tag_id:   
     type: integer 
    name:    
     type: string(100) 
    relations: 
    Tag: 
     class: Tag 
     refClass: TagNews 
     local: news_id 
     foreign: tag_id 
     foreignAlias: TagNews 


TAG: 
| id | name | 
| 1 | tag1 | 
| 2 | tag2 | 
| 3 | tag3 | 


TagNews: 
| id_tag | tag_news | 
| 1  | 1  | 
| 2  | 1  | 
| 2  | 2  | 
| 3  | 2  | 
| 3  | 3  | 
| 1  | 3  | 

News: 

| id | name | 
| 1 | news1 | 
| 2 | news2 | 
| 3 | news3 | 
| 4 | news4 | 
| 5 | news5 | 

我怎樣才能得到tag1等所有新聞?得到多對多的關係

例如site.com/tag/tag1? 我必須在action.class和template中寫什麼?我使用的Symfony 1.4學說和1.2

回答

1
$tag = TagTable::getInstance()->find(1); 
$news = $tag->getNews(); 

應該工作..否則,你就必須定義有關消息,在標籤(相同新聞標籤)