Doctrine ORM学说中的观点

Doctrine ORM学说中的观点,doctrine,Doctrine,我在处理学说中的观点时遇到了一个问题 我的数据库中有以下视图: $q = Doctrine_Query::create() ->select('c.id, c.name, m.id, m.name, m.status, m.modified, m.entered, m.accountid') ->from('Catego

我在处理学说中的观点时遇到了一个问题

我的数据库中有以下视图:

$q = Doctrine_Query::create()
                        ->select('c.id, c.name, m.id, m.name, m.status, 
                                  m.modified, m.entered, m.accountid')
                        ->from('Category c')
                        ->leftJoin('c.Mailing m');
$view = new Doctrine_View($q, 'view_mailings');
$q->execute(array(), Doctrine::HYDRATE_ARRAY);
结果包括所有记录。但是,我需要获取一个子集 基于accountid的不同值,按不同的顺序排序 柱。我怎样才能做到这一点


谢谢你的帮助

您只是执行查询$q,而没有使用您创建的视图。

另一种解决方案可能是在config/doctor/中为视图创建模式,如下所示:

objective:
  tableName: objective
  columns:
    id:
      type: integer
    zone:
      type: string(50)
    province:
      type: string(30)
    city:
      type: string(100)
    population:
      type: integer
    city_obj_id:
      type: integer
    clinic_number:
      type: integer
    clinic_obj:
      type: integer
    comments:
      type: string(255)
DROP VIEW IF EXISTS objective;
DROP TABLE IF EXISTS objective;
CREATE VIEW objective AS
    SELECT
    c.id as id,
    z.name as zone,
    p.name as province,
    c.name as city,
    cs.amount as population,
    co.id as city_obj_id,
    co.clinic_num as clinic_number,
    co.clinic_obj as clinic_obj,
    co.comments as comments

    FROM
    city c left join city_objective co on co.city_id = c.id
    left join city_census cs on (cs.city_id = c.id and cs.year = 2009)
    left join province p on p.id = c.province_id
    left join zone z on z.id = p.zone_id;
然后将objective_view.sql放入data/sql/中,如下所示:

objective:
  tableName: objective
  columns:
    id:
      type: integer
    zone:
      type: string(50)
    province:
      type: string(30)
    city:
      type: string(100)
    population:
      type: integer
    city_obj_id:
      type: integer
    clinic_number:
      type: integer
    clinic_obj:
      type: integer
    comments:
      type: string(255)
DROP VIEW IF EXISTS objective;
DROP TABLE IF EXISTS objective;
CREATE VIEW objective AS
    SELECT
    c.id as id,
    z.name as zone,
    p.name as province,
    c.name as city,
    cs.amount as population,
    co.id as city_obj_id,
    co.clinic_num as clinic_number,
    co.clinic_obj as clinic_obj,
    co.comments as comments

    FROM
    city c left join city_objective co on co.city_id = c.id
    left join city_census cs on (cs.city_id = c.id and cs.year = 2009)
    left join province p on p.id = c.province_id
    left join zone z on z.id = p.zone_id;

通过这种方式,目标表将填充更新的数据,您可以对其执行查询以轻松获取相关信息

对不起,你的回答没有多大意义。如果我想使用直接查询,我根本不会费心在数据库中创建视图。我可以看到这个问题很久以前就被悄悄地发布了!你是怎么处理的?或者您是否找到了其他更好的方法来处理条令视图?如何执行
objective\u view.sql
insert sql
任务似乎无法完成…@PeterTaylor:如果执行
symfony原则:build--all--and load
它将执行data/sql/文件夹中的所有sql脚本。。。