0

在 Symfony 1.4,Doctrine 我有这个来自 schema.yml 的片段

Attendance:
  columns:
    id: { type: integer(4), primary: true, autoincrement: true }
    user_id: { type: integer(4) }

  relations:
    JoomlaUser: { class: JosUser, local: user_id, foreignAlias: AttendanceList }

JosUser:
  tableName: jos_users
  columns:
    id: { type: integer(4), primary: true, autoincrement: true }
  relations:
    AttendanceList: { class: Attendance, local: id, foreign: user_id }

从 JosUser 确定没有出勤记录的最有效方法是什么。我试过模型/教义/JosUser.class.php

count($this->getAttendanceList())

但这会返回一个所有字段为空但 user_id 的 Doctrine 记录

4

1 回答 1

1

架构:

JosUser:
    tableName: jos_users
    columns:
        id: { type: integer(4), primary: true, autoincrement: true }
    relations:
    AttendanceList: { type: many, class: Attendance, local: id, foreign: user_id }

使用type: many,getAttendanceList()应该返回一个 Doctrine_Collection(参见 lib/model/doctrine/base/BaseJosUser.class.php 中的 JosUser 基类),然后您可以使用

$this->getAttendanceList()->count()

于 2013-05-06T14:08:12.763 回答