1

我正在尝试使用友好名称(模型中的虚拟字段)检索 id 列表,但我继续在虚拟字段上获取未知列。有任何想法吗?

  public $virtualFields = array(
        'friendly_name' => "CONCAT(ReAgent.first_name, ' ',ReAgent.last_name)"
  );

 $results = $this->Re->find("all",
                array("recursive" => 0, 
                    "fields" => array("Re.id","ReAgent.friendly_name"),
                    "contains" => array(
                        "RegroupsRe" => 
                            array("conditions" => 
                                array(
                                    "regroup_id" => $post[$field]
                                )
                            )
                        ),
                        "ReAgent" => array(
                            "fields" => "friendly_name"
                        )
                    )
                );
4

1 回答 1

1

该虚拟字段在哪里指定,Re 或 ReAgent?

如果它在 Re 模型中,则将“字段”参数删除到包含中的 ReAgent 模型(顺便说一下,它应该是单数)......

$results = $this->Re->find(
    "all",
    array(
        "recursive" => 0, 
        "fields" => array("Re.id", "ReAgent.friendly_name"),
        "contain" => array(
            "RegroupsRe" => array(
                "conditions" => array(
                    "regroup_id" => $post[$field]
                ),
            ),
            "ReAgent",
        )
    )
);

你也有 ReAgent 在你的容器之外,这不会有帮助!上述样品已清理干净。

于 2012-09-05T12:11:20.723 回答