Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Collections 推进-合并集合_Collections_Propel - Fatal编程技术网

Collections 推进-合并集合

Collections 推进-合并集合,collections,propel,Collections,Propel,使用PropeOrm1.5时,我缺少一种合并两个属性集合的方法 简短的提案可以是: 公共函数合并集合($collection){ foreach($i=>$item的集合){ 如果(!$this->包含($item)){ //附加项 $this->append($item); } } } 所以我是一个新手,我想问你,是否有更好的方法 或者这个功能已经包含在Prope中了,但我还没有发现它?它似乎已经在邮件列表中,但我找不到票证 至少,您可以尝试此代码和/或 /** *添加元素集合,防止重复 *

使用PropeOrm1.5时,我缺少一种合并两个
属性集合的方法

简短的提案可以是:

公共函数合并集合($collection){
foreach($i=>$item的集合){
如果(!$this->包含($item)){
//附加项
$this->append($item);
}
}
}
所以我是一个新手,我想问你,是否有更好的方法 或者这个功能已经包含在Prope中了,但我还没有发现它?

它似乎已经在邮件列表中,但我找不到票证

至少,您可以尝试此代码和/或

/**
*添加元素集合,防止重复
*
*@param array$collection集合
*
*@return int集合中新元素的数目
*/
公共函数addCollection($collection)
{
$i=0;
foreach($ref形式的集合){
如果($this->add($ref)){
$i=$i+1;
}
}
返回$i;
}
/**
*向集合中添加元素,以防止重复
*
*@param$element元素
*
*@return bool,如果元素是否已添加
*/
公共功能添加($element)
{
如果($element!=NULL){
如果($this->isEmpty()){
$this->append($element);
返回true;
}否则如果(!$this->contains($element)){
设置错误处理程序(“错误2异常”);
试一试{
如果(!method_存在($element,'getPrimaryKey')){
还原错误处理程序();
$this->append($element);
返回true;
}
如果($this->get($element->getPrimaryKey())!=null){
还原错误处理程序();
返回false;
}否则{
$this->append($element);
还原错误处理程序();
返回true;
}
}捕获(例外$x){
//这是我的收藏
restore_error_handler();//还原旧的处理程序
$this->append($element);
返回true;
}
restore_error_handler();//还原旧的处理程序
}
}
返回false;
}
}
函数错误\u 2\u异常($errno、$errstr、$errfile、$errline、$context){
抛出新异常(“”,$errno);
返回true;
}

好的,我也通过搜索邮件列表找到了这段代码。这似乎是做这件事的方法!关于如何在现有项目中集成这些函数,防止手动更改PropertCollection类,您有什么想法吗?嗯,我想在不更改PropertCollection的情况下集成这些函数会很复杂(可能是等待修补程序合并的临时修复)。正如Francois在ML上所说的,编写一个带有单元测试的补丁,并将其发布到PropeGithub上,那么您的函数可能会出现在下一个Propel版本中。