在 schema.yml 中设置 Doctrine_Collection 键映射属性
在 Doctrine 1.2 中,可以设置 键映射 用于表,其中由该表创建的 Doctrine_Collection
对象将从集合中每条记录的特定列填充键。
上面链接的文档中的示例:
您可能想要映射名称列:
//test.php // ... $userTable = Doctrine_Core::getTable('用户'); $userTable->setAttribute(Doctrine_Core::ATTR_COLL_KEY, '用户名');
现在用户集合将使用名称列的值作为元素索引:
//test.php // ... $users = $userTable->findAll(); foreach($users as $username => $user) { 回显$用户名。 '-'。 $user->created_at 。 “\n”; }
有没有办法在 schema.yml 文件中进行设置?
In Doctrine 1.2, it is possible to set up Key Mapping for a table where Doctrine_Collection
objects created by that table will populate keys from a particular column in each record in the collection.
An example from the documentation linked above:
You may want to map the name column:
// test.php // ... $userTable = Doctrine_Core::getTable('User'); $userTable->setAttribute(Doctrine_Core::ATTR_COLL_KEY, 'username');
Now user collections will use the values of name column as element indexes:
// test.php // ... $users = $userTable->findAll(); foreach($users as $username => $user) { echo $username . ' - ' . $user->created_at . "\n"; }
Is there a way to set this up in a schema.yml file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在探索类似的问题时,我遇到了 这个例子:
对 coll_key 属性应用相同的原则会产生以下结果:
我们可以在构建后验证该属性是否被接受:
不过,有一个警告。您必须显式创建要使用的列,否则 Doctrine 将在构建过程中抛出错误:
要使上述工作正常,您需要显式指定
slug
列,甚至尽管Sluggable
模板通常会自动为您创建它:While exploring a similar issue, I came across this example:
Applying the same principle with the
coll_key
attribute yields this:We can verify after doing a build that the attribute was accepted:
There is one caveat, though. You have to explicitly create the column that you want to use, or else Doctrine will throw an error during the build process:
To get the above to work, you would need to explicitly specify the
slug
column, even though theSluggable
template normally creates it for you automatically:如果可能的话,也没有很好的记录。
您可以在表定义中指定表的选项, 像这样
知道
我会尝试:
然后
甚至
我无法准确找到代码中处理选项的位置,但您可以使用 xdebug 逐步调试来完成此操作。
祝你好运,并告诉用户这些尝试之一是否有效。
If it is possible, it is not well documented.
You can specify options for a table in the table definition, like this
Knowing that
I would try :
then
or even
I couldn't find precisely where in the code the options are handled, but you could do this with xdebug step-by-step debugging.
Good luck, and tell use if one of these tries works.