使用 doctrine 2 DQL 铸造布尔类型

casting boolean type with doctrine 2 DQL

我有一个学说实体 A,它有一个布尔类型的字段 'attendance'。该字段的值在 postgres 中存储为 t 和 f。 我想编写一个 DQL,它将给我的字段值为 1 或 0。我可以在 SQL 中使用 postgressql cast 语句执行相同的操作,如下所示:

"select attendance::int from class where student = 1"

Doctrine 扩展提供 CAST function. Another option is NativeQuery 或纯 SQL 查询(如果您不需要映射)。