小编Jas*_*Lin的帖子

$ find在数组中的ObjectId

在一个ObjectIds数组而不仅仅是一个ObjectId的字段上执行$ lookup的语法是什么?

示例订单文档:

{
  _id: ObjectId("..."),
  products: [
    ObjectId("..<Car ObjectId>.."),
    ObjectId("..<Bike ObjectId>..")
  ]
}
Run Code Online (Sandbox Code Playgroud)

不工作查询:

db.orders.aggregate([
    {
       $lookup:
         {
           from: "products",
           localField: "products",
           foreignField: "_id",
           as: "productObjects"
         }
    }
])
Run Code Online (Sandbox Code Playgroud)

期望的结果

{
  _id: ObjectId("..."),
  products: [
    ObjectId("..<Car ObjectId>.."),
    ObjectId("..<Bike ObjectId>..")
  ],
  productObjects: [
    {<Car Object>},
    {<Bike Object>}
  ],
}
Run Code Online (Sandbox Code Playgroud)

mongodb mongodb-query aggregation-framework

86
推荐指数
5
解决办法
8万
查看次数

类在AppKernel.php中找不到

我正在尝试部署我的Symfony2项目.当我运行命令

php app/console cache:clear --env=prod --no-debug
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

PHP Fatal error: Class 'Acme\MainBundle\AcmeMainBundle' not found in /var/www/html/app/AppKernal.php on line 24
Run Code Online (Sandbox Code Playgroud)

这是在AppKernal.php中

public function registerBundles()
{
    $bundles = array(
        ...
        new Acme\MainBundle\AcmeMainBundle(),
    );
    ...
}
Run Code Online (Sandbox Code Playgroud)

似乎命名空间存在问题?

php deployment namespaces symfony

9
推荐指数
4
解决办法
2万
查看次数

Doctrine单表继承查询所有实例

我正在研究通知系统,所以我有一个通知抽象类和子类(forumPostNotification,privateMessageNotification等).它们使用单​​表继承存储,因此它们都在一个具有区分字段的表中.

我希望立即获得适用于用户的所有通知,而不必单独查询每种类型的通知,但是我不确定如何在DQL/symfony中执行此操作(在SQL中这很容易).

我相信这一点:( 主义2:如何编写一个DQL select语句来搜索一些,但不是单个表继承表中的所有实体)类似于我想要实现的,但我不知道如何查询抽象对象.它也不在Entity目录中,而是在Entity/Notifications/Notification.php中.

我将添加一些代码以便澄清:

Notification.php

/**
 * Notification Class    
 *@ORM\Entity
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorColumn(name="type", type="string")
 * @ORM\DiscriminatorMap({
 *     "notification"="Notification",
 *     "forumPostNotification"="ForumPostNotification",
 *     ...
 * })
 * @ORM\Table(name="notification")
 */
abstract class Notification
{
  /**
   * @ORM\ManyToOne(targetEntity="Acme\MainBundle\Entity\User", inversedBy="notifications")
   * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
   */
  private $user;
  //...
}
Run Code Online (Sandbox Code Playgroud)

ForumPostNotification.php

/**
 * Forum Post Notification
 * @ORM\Entity
 */
class ForumPostNotification extends Notification
{
  //..
}
Run Code Online (Sandbox Code Playgroud)

PrivateMessageNotification.php

/**
 * Private Message Notification
 * @ORM\Entity
 */
class PrivateMessageNotification extends Notification
{
  //..
}
Run Code Online (Sandbox Code Playgroud)

我希望能够以这样或那样的方式做这样的事情(我明白我不能从Notification中查询,因为它是一个抽象类.我只是这样写它来传达我想要实现的东西): …

php doctrine single-table-inheritance dql symfony

5
推荐指数
1
解决办法
2534
查看次数

jQuery offset().top 每隔一段时间稍微关闭一次

我试图让父 div 的内部以设定的间隔滚动到下一个子 div。然而,滚动只工作了一半,我不知道为什么。它应该滚动浏览所有 8 个孩子,但只浏览大约一半。

在我制作的这个 jsfiddle 中,当它应该是 ~250px 时,每隔一次偏移量只是 1px。在我的实际代码中,它关闭了 0px,而它应该关闭了 ~250px。

https://jsfiddle.net/rLeLogx0/3/

这是JS:

//scroll to 2nd one first
var index = 1;

setInterval(function(){
    var parent = $('.parent');
    var children = parent.find('.child');
    var target = children.eq(index);   
    var offset = target.offset().top - $('.parent').offset().top;

    //ISSUE: outputs the "same" value every other time
    console.log(target.offset().top);

    parent.animate({
        scrollTop: offset
    }, 200);
    index = (index+1) % children.length;
}, 1000);
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery

3
推荐指数
1
解决办法
2525
查看次数