有没有方便的方法可以让我连接两个Doctrine ArrayCollection()?就像是:
$collection1 = new ArrayCollection();
$collection2 = new ArrayCollection();
$collection1->add($obj1);
$collection1->add($obj2);
$collection1->add($obj3);
$collection2->add($obj4);
$collection2->add($obj5);
$collection2->add($obj6);
$collection1->concat($collection2);
// $collection1 now contains {$obj1, $obj2, $obj3, $obj4, $obj5, $obj6 }
Run Code Online (Sandbox Code Playgroud)
我只是想知道我是否可以保存我迭代第二个集合并逐个添加每个元素到第一个集合.
谢谢!
我可以在使用延迟加载时从Doctrine 2中的arrayCollection中过滤出结果吗?例如,
// users = ArrayCollection with User entities containing an "active" property
$customer->users->filter('active' => TRUE)->first()
Run Code Online (Sandbox Code Playgroud)
我不清楚滤波器方法是如何实际使用的.
我有一个实体订单,它将供应商保存在Arraycollection中.在我的控制器中,我想检查此arraycollection是否为空:
$suppliers = $order->getSuppliers();
Run Code Online (Sandbox Code Playgroud)
我试过了:
if(!($suppliers)) {}
if(empty($suppliers)) {}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
如何检查Doctrine Collection(ManyToMany关系)字段中是否存在给定值?
例如,我尝试:
$someClass = $this->
getDoctrine()->
getRepository('MyBundle:MyClass')->
find($id);
if (!$entity->getMyCollectionValues()->get($someClass->getId())) {
$entity->addMyCollectionValue($someClass);
}
Run Code Online (Sandbox Code Playgroud)
但这当然不正确.那么,如何避免重复键?
在我的模型中,我有一个食谱实体和成分实体.在Recipe实体中,关系定义如下:
/**
* @ORM\OneToMany(targetEntity="Ingredient", mappedBy="recipe", cascade={"remove", "persist"}, orphanRemoval=true)
* @ORM\OrderBy({"priority" = "ASC"})
*/
private $ingredients;
Run Code Online (Sandbox Code Playgroud)
在Ingredient实体中:
/**
* @ORM\ManyToOne(targetEntity="Recipe", inversedBy="ingredients")
* @ORM\JoinColumn(name="recipe_id", referencedColumnName="id")
*/
private $recipe;
Run Code Online (Sandbox Code Playgroud)
我正在研究配方的CRUD控制器,我希望用户能够动态添加配料.我还希望用户拖放成分以在配方中设置其优先级(顺序).我正在使用CollectionType表单字段.
这个页面作为教程:
http://symfony.com/doc/current/cookbook/form/form_collections.html
到目前为止,添加和显示配方工作正常,但是编辑/更新操作存在问题,我将在下面尝试描述:
在控制器中,我加载实体并创建如下形式:
public function updateAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$recipe = $em->getRepository('AppBundle:Recipe')->find($id);
$form = $this->createEditForm($recipe);
$form->handleRequest($request);
...
}
Run Code Online (Sandbox Code Playgroud)
由于优先级保存在DB中,而且我有@ORM\OrderBy({"priority" = "ASC"}),原料的初始加载和显示工作正常.但是,如果用户拖放成分,则优先级值会发生变化.如果存在表单验证错误并且需要重复显示表单,则表单中的成分将按旧顺序显示,即使优先级值已更新.
例如,我在DB中有以下初始Ingredient => priority值:
表格行按顺序显示:A,B,C;
用户更改订单后,我有:
但表格行仍然显示为A,B,C;
我知道表单已经用A,B,C顺序初始化,并且更新priority …
我想通过flex 3中的函数将arrayCollection#2 =设置为arrayCollection#1.我将两个数组都传递给一个函数并设置arrayCollection#2 = arrayCollection#1.但是,似乎没有通过引用传递arrayCollection#2,因为在函数调用之后,arrayCollection#2没有被更改.我的理解是它应该通过引用和工作传递,我做错了什么?以下是代码:
var AC1:ArrayCollection = new ArrayCollection;
var AC1.addItem(someObject);
var AC2:ArrayCollection = new ArrayCollection;
setAC2(AC1,AC2);
// AC2 is not set to AC1 after the function
private function setAC2(_ac1:ArrayCollection, _ac2:ArrayCollection):void
{
_ac2 = _ac1;
}
Run Code Online (Sandbox Code Playgroud) 我在symfony2(doctrine)中使用以下代码作为我的多对多关系
实体:
/**
* @ORM\ManyToMany(targetEntity="BizTV\ContainerManagementBundle\Entity\Container", inversedBy="videosToSync")
* @ORM\JoinTable(name="syncSchema")
*/
private $syncSchema;
public function __construct()
{
$this->syncSchema = new \Doctrine\Common\Collections\ArrayCollection();
}
public function addSyncSchema(\BizTV\ContainerManagementBundle\Entity\Container $syncSchema)
{
$this->syncSchema[] = $syncSchema;
}
Run Code Online (Sandbox Code Playgroud)
控制器:
$entity->addSyncSchema($container);
$em->flush();
Run Code Online (Sandbox Code Playgroud)
现在,我该如何使用它来删除关系?我是否需要向我的实体添加方法,如removeSyncSchema()?那会是什么样的?
不幸的是,在Actionscript中,似乎对Vector类的支持尚不完全.在某些情况下,我需要将Vector转换为数组(例如,创建一个ArrayCollection).我认为这样可以解决问题:
var myVector:Vector.<MyType> = new Vector.<MyType>();
var newArray:Array = new Array(myVector);
Run Code Online (Sandbox Code Playgroud)
显然,这只是创建一个数组,其中数组的第一个索引包含完整的Vector对象.这是我唯一的选择:
var newArray:Array = new Array(myVector);
for each(var item:MyType in myVector)
{
newArray.push(item);
}
Run Code Online (Sandbox Code Playgroud)
我觉得这会使代码混乱很多,我需要在很多地方做到这一点.Vector类没有实现任何类型的接口,所以据我所知,我不能创建一个通用函数来转换为数组.有没有办法这样做,而不是每次我想将Vector转换为数组时都添加这个混乱?
通过BlazeDS将对象从ColdFusion推送到Flex,并使用RemoteClass映射类...
[RemoteClass(alias="blah.blah")]
Run Code Online (Sandbox Code Playgroud)
...是否可以将ColdFusion"Arrays"(或某些Java等价物)自动映射到ActionScript ArrayCollections?
这个家伙几乎拥有它,但并不完全:
http://www.richinternet.de/blog/index.cfm?mode=entry&entry=33CF66A4-DC95-6312-95EFE8E3DB31D298
我有一个带有ArrayCollection字段的实体.在我可以写的注释中
@ORM\OrderBy({"somefield" = "DESC"})
我将从该实体获得的集合将自动订购.
我的问题是,是否可以通过聚合字段进行排序?
我当前的问题:我在集合实体中有2个字段:visited而且shown,我想用评级索引对集合进行排序,即:visited / shown.我试着在注释中写它,但它说它应该是一个有效的字段.我知道如何使用DQL执行此操作,但我不知道如何使用注释在Entity的声明中重新创建它.
提前致谢!
arraycollection ×10
symfony ×6
doctrine-orm ×5
apache-flex ×3
php ×3
actionscript ×2
arrays ×1
blazeds ×1
coldfusion ×1
database ×1
doctrine ×1
forms ×1
lazy-loading ×1
orm ×1
sql-order-by ×1
symfony-2.2 ×1
vector ×1