小编Kon*_*nia的帖子

YII中的关系不是"ID"作为主键

我有一个模型Anketa,它user_id不仅仅是主键id.我想为它创建一个HAS_ONE关系,所以我编码:

function relations()
{
return array(
...
'last_experience' => array(
    self::HAS_ONE, 'Experience', 'user_id',
    'condition' => '
        `signoff` = (
        SELECT MAX( `signoff` )
        FROM `experience` AS t2
        WHERE t2.user_id = last_experience.user_id )
    ',
),  
);
}
Run Code Online (Sandbox Code Playgroud)

但是当我试图获得这个属性时,我得到"Property"Anketa.id"没有定义." 错误.

我在CActiveFinder.php文件中找到了一些执行以下操作的代码:

if($this->relation instanceof CBelongsToRelation)
{
    if(is_int($i))
    {
        if(isset($parent->_table->foreignKeys[$fk]))  // FK defined
            $pk=$parent->_table->foreignKeys[$fk][1];
        else if(is_array($this->_table->primaryKey)) // composite PK
            $pk=$this->_table->primaryKey[$i];
        else
            $pk=$this->_table->primaryKey;
    }
    $params[$pk]=$record->$fk;
}
Run Code Online (Sandbox Code Playgroud)

此块id由于某种原因而不是返回user_id.我不知道这是不是一个错误,因为其他关系工作正常,但它们并不像这个那么复杂.

为什么会这样?我怎样才能解决这个问题?

谢谢!

yii

2
推荐指数
1
解决办法
4189
查看次数

为node.js构建libxmljs时出错

我在我的mac os x 10.9.3上构建libxmljs时遇到了问题.

这是我得到的:

3 warnings generated.
  CC(target) Release/obj.target/libxml/vendor/libxml/xpointer.o
  LIBTOOL-STATIC Release/xml.a
libtool: unrecognized option `-static'
libtool: Try `libtool --help' for more information.
make: *** [Release/xml.a] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Darwin 13.2.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/libxmljs
gyp ERR! node -v v0.10.13 …
Run Code Online (Sandbox Code Playgroud)

macos node.js node-gyp libxml-js

2
推荐指数
1
解决办法
1747
查看次数

为什么mongo聚合在shell中工作但在PHP中超过16MB

我有一个非常庞大的mongo聚合命令.

db.container_product.aggregate([
    {"$unwind":"$product"},
    {"$group":{"_id":"$product","container_ids":{"$push":"$container_id"}}}
])
Run Code Online (Sandbox Code Playgroud)

它产生了近5k组,但它们都是普通的整数.例如:

{ 
    "_id" : NumberInt(107058402), 
    "container_ids" : [
        NumberInt(107058409), 
        NumberInt(107058410), 
        NumberInt(107058411), 
        NumberInt(107058412), 
        NumberInt(107058413)
    ]
}
Run Code Online (Sandbox Code Playgroud)

当我在shell(普通shell,还有Robomongo等)中运行它时它工作得很好.但是当我尝试从PHP运行它时,它给了我16MB的错误.

172.16.0.2:27017: exception: aggregation result exceeds maximum document size (16MB)

在这种情况下,PHP和shell之间的巨大差异是什么?

我怎么解决这个问题?

php mongodb mongo-shell

2
推荐指数
1
解决办法
97
查看次数

如何仅模拟/存根案例类中的一个字段

我看过很多关于在使用scalamock测试时如何模拟案例类中的方法的文章。

然而,有时我只需要模拟一个字段。例如,当我测试一个非常狭窄的工作流程时。

我认为这stub[Type].copy(f = "1")会起作用,但它只返回null.

您也不能像方法一样模拟该字段:

val x = mock[Type]
( x.f _ ).when().then("1")
Run Code Online (Sandbox Code Playgroud)

这也不会编译。

在这种情况下有什么解决方法?在这种情况下,最佳做法是什么?我真的应该定义不需要测试的整个案例类字段吗?

scala mocking scalamock

2
推荐指数
1
解决办法
1439
查看次数

标签 统计

libxml-js ×1

macos ×1

mocking ×1

mongo-shell ×1

mongodb ×1

node-gyp ×1

node.js ×1

php ×1

scala ×1

scalamock ×1

yii ×1