0

「多くの」テーブルレコードからオブジェクトを取得する方法は?

のリストがrsObjectCommentsあり、フェッチする必要がありrsObjectsます。

例えば:

schema.yml:

rsObject:
  actAs:
    Timestampable: ~ 
    Sluggable:
      fields: [name]
  columns:
    name: { type: string(255), notnull: true, unique: true }
    description:  { type: string(6000), notnull: true }
  relations:
    rsObjectComments:
     class:        rsObjectComments
     local:        id
     foreign:      rsobject_id
     type:         many
     foreignAlias: Comments

rsObjectComments:
  actAs:
    Timestampable: ~
  columns:
    rsobject_id: { type: integer, notnull: true }
    fromname: { type: string(100), notnull:true }
    fromemail: { type: string(100), notnull:true }
    comments: { type: string(1000), notnull:true }    
    is_public: { type: boolean, notnull: true, default: 1 }
  relations:
    rsObject: { onDelete: CASCADE, local: rsobject_id, foreign: id, foreignAlias: rsObjectCommentsAlias } 
4

1 に答える 1

0

Inside The Model Layer (Doctrine) (特に関連レコードの取得部分)というドキュメント ページ全体を読むことをお勧めします。

多くのコメントを含む記事の基本的な例が表示されます (これはあなたのものとほとんど同じです)。

あなたの例では、次を使用してrsObject関連を取得できる場合rsObjectComments

// will return a Doctrine_Collection
$rsObjectComments = $rsObject->getComments();

withgetCommentsを定義したので使用しています。foreignAliasComments

そして、あなたがそれらに取り組みたいのなら

foreach ($rsObject->getComments() as $comment)
{
  // $comment is a rsObjectComments object
}

逆の順序で、コメントがあり、その記事を取得したい場合。

$rsObject = $comment->getRsObject();
于 2012-08-29T08:52:00.737 に答える