我有一个事件,它有一个权限,这个权限引用了一个用户。我正在尝试获取与用户关联的所有事件,但我似乎无法按照我的意愿让原则发挥作用。
这是我的 Mongo 模式
Array
(
[_id] => 4e63903cbc3470a2cd000002
[date] => 2011-10-09
[name] => Event1
[privileges] => Array
(
[0] => Array
(
[user] => Array
(
[$ref] => users
[$id] => 4e63611cbc347053a2000001
[$db] => eventdb
)
[role] => admin
)
)
[url] => Event1
)
学说事件实体:
class Event {
/**
* @Id
*/
protected $id;
/**
* @String
*/
protected $name;
/**
* @EmbedMany(targetDocument="\Event\Privilege")
*/
protected $privileges = array();
}
特权实体:
class Privilege {
/**
* @ReferenceOne(targetDocument="\User", cascade={"persist"})
*/
protected $user;
/**
* @String
*/
protected $role;
}
和用户实体:
class User {
/**
* @Id
*/
protected $id;
/**
* @String
*/
private $firstname;
/**
* @String
*/
private $lastname;
/**
* @String
*/
protected $username;
}
我尝试了以下但没有成功
Example 1:
$privilege_repository = $dm->getRepository('\Event\Privilege');
$qb1 = $privilege_repository->createQueryBuilder('\Event\Privilege') ->field('user.$id')->equals('4e63611cbc347053a2000001');
$query1 = $qb1->getQuery();
$result1 = $query1->execute();
$result1->count() :0
Example 2:
$privilege_repository = $dm->getRepository('\Event\Privilege');
$qb2 = $privilege_repository->createQueryBuilder('\Event\Privilege') ->field('user.$id')->equals(new \MongoId('4e63611cbc347053a2000001'));
$query2 = $qb2->getQuery();
$result2 = $query2->execute();
$result2->count() :0
Example 3:
$privilege_repository = $dm->getRepository('\Event\Privilege');
$qb3 = $privilege_repository->createQueryBuilder('\Event\Privilege') ->field('user')->equals(new \MongoId('4e63611cbc347053a2000001'));
$query3 = $qb3->getQuery();
$result3 = $query2->execute();
$result3->count() :0
我也尝试过使用 Event 类,但并没有取得更大的成功……我肯定遗漏了一些东西,但我不知道是什么!欢迎任何帮助。
谢谢。
最佳答案
** 一晚后 ** 终于成功了!
Example 2:
$privilege_repository = $dm->getRepository('\Event');
$qb2 = $privilege_repository->createQueryBuilder('\Event') ->field('privileges.user.$id')->equals(new \MongoId('4e63611cbc347053a2000001'));
$query2 = $qb2->getQuery();
$result2 = $query2->execute();
$result2->count() :3
你真的需要使用新的 MongoId() 否则它总是返回空!
关于php - Doctrine ODM/PHP/MongoDB - 无法查询引用的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7300358/
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我正在用Ruby编写一个简单的程序来检查域列表是否被占用。基本上它循环遍历列表,并使用以下函数进行检查。require'rubygems'require'whois'defcheck_domain(domain)c=Whois::Client.newc.query("google.com").available?end程序不断出错(即使我在google.com中进行硬编码),并打印以下消息。鉴于该程序非常简单,我已经没有什么想法了-有什么建议吗?/Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/base.
我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
我在pry中定义了一个函数:to_s,但我无法调用它。这个方法去哪里了,怎么调用?pry(main)>defto_spry(main)*'hello'pry(main)*endpry(main)>to_s=>"main"我的ruby版本是2.1.2看了一些答案和搜索后,我认为我得到了正确的答案:这个方法用在什么地方?在irb或pry中定义方法时,会转到Object.instance_methods[1]pry(main)>defto_s[1]pry(main)*'hello'[1]pry(main)*end=>:to_s[2]pry(main)>defhello[2]pry(main)
我知道我可以指定某些字段来使用pluck查询数据库。ids=Item.where('due_at但是我想知道,是否有一种方法可以指定我想避免从数据库查询的某些字段。某种反拔?posts=Post.where(published:true).do_not_lookup(:enormous_field) 最佳答案 Model#attribute_names应该返回列/属性数组。您可以排除其中一些并传递给pluck或select方法。像这样:posts=Post.where(published:true).select(Post.attr
我使用的是Firefox版本36.0.1和Selenium-Webdrivergem版本2.45.0。我能够创建Firefox实例,但无法使用脚本继续进行进一步的操作无法在60秒内获得稳定的Firefox连接(127.0.0.1:7055)错误。有人能帮帮我吗? 最佳答案 我遇到了同样的问题。降级到firefoxv33后一切正常。您可以找到旧版本here 关于ruby-无法在60秒内获得稳定的Firefox连接(127.0.0.1:7055),我们在StackOverflow上找到一个类
当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub