带有MSSQL的Doctrine返回同一个孩子

时间:2016-03-22 16:17:57

标签: sql-server symfony doctrine-orm

我正在使用现有的MSSQL数据库(Dynamics)并从中获取数据我已经在Doctrine实体中克隆了数据库布局,因此我可以从数据库中获取数据。这适用于唯一的实体,但是当我有OneToMany关系时,出现问题。它返回了正确数量的孩子,但他们都是一样的。

当我将可运行查询粘贴到SQL Server时,我得到了正确的结果(使用不同的子代)。所以SQL查询很好。

因此,似乎Doctrine没有正确地补充结果。我正在使用pdo_sqlsrv驱动程序和Doctrine2与Symfony 2.8。

动态表格布局:

PurchTable
recid = unique integer
purchid = unique string

PurchLine
recid = unique integer
purchid = referring to purchid from PurchTable
itemid = string
etc...

PurchTable实体:

 /**
 * @var integer
 *
 * @ORM\Column(name="recid", type="integer")
 */
private $recid;

/**
 * @var string
 *
 * @ORM\Column(name="purchid", type="string", length=255)
 * @ORM\Id
 */
private $orderid;

/**
 * @ORM\OneToMany(targetEntity="PurchLine", mappedBy="order")
 */
protected $lines;

public function __construct()
{
    $this->lines = new ArrayCollection();
}

PurchLine:

/**
 * @var integer
 *
 * @ORM\Column(name="recid", type="integer")
 * @ORM\Id
 */
private $recid;

/**
 * @var integer
 *
 * @ORM\Column(name="linenum", type="integer")
 */
private $linenum;

/**
 * @var string
 *
 * @ORM\Column(name="itemid", type="string", length=255)
 */
private $itemid;

/**
 * @ORM\ManyToOne(targetEntity="PurchTable", inversedBy="lines")
 * @ORM\JoinColumn(name="purchid", referencedColumnName="purchid")
 */
protected $order;

正如您所看到的,我在PurchTable中将属性名称更改为orderid以避免使用相同的名称,但这并没有帮助。

那么我做错了什么? :)

我无法在短时间内更改驱动程序,因此我想知道这是否是驱动程序问题(更改驱动程序的更改优先级)。看完之后:

http://doctrine-orm.readthedocs.org/projects/doctrine-dbal/en/latest/reference/configuration.html#driver

使用pdo_sqlsrv PDO的Microsoft SQL Server驱动程序请注意,此驱动程序在我们的测试中导致了问题。如果可能,请更喜欢sqlsrv驱动程序。

我想知道pdo_sqlsrv驱动程序是否会导致这些问题。

修改

我测试了sqlsrv驱动程序(确保使用空字符串作为用户名而不是null(对于pdo_sqlsrv)来使用Windows身份验证)我遇到了同样的问题。所以它必须是学说或关系中的东西。

编辑2

我重新创建了实体,以避免任何拼写错误,但无济于事。

1 个答案:

答案 0 :(得分:0)

问题在于列的错误定义。 MSSQL数据库中的RecId列是bigint而不是整数。

所以,改变

angular.js:9959 Error: Failed to execute 'replaceState' on 'History': A history state object with URL 'file:///Users/Javier/codez/flapper_news/index.html#/home' cannot be created in a document with origin 'null' and URL 'file:///Users/Javier/codez/flapper_news/index.html'.
    at Error (native)
    at te.k.url (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js:39:227)
    at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js:91:187
    at k.$eval (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js:112:319)
    at k.$digest (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js:109:392)
    at k.$apply (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js:113:100)
    at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js:18:239
    at Object.d [as invoke] (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js:35:36)
    at c (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js:18:147)
    at cc (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js:18:356)(anonymous function) @ angular.js:9959(anonymous function) @ angular.js:7298k.$digest @ angular.js:12410k.$apply @ angular.js:12699(anonymous function) @ angular.js:1418d @ angular.js:3917c @ angular.js:1416cc @ angular.js:1430Xc @ angular.js:1343(anonymous function) @ angular.js:21773a @ angular.js:2549(anonymous function) @ angular.js:2822q @ angular.js:325c @ angular.js:2821
angular.js:8467 XMLHttpRequest cannot load file:///home.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

/**
 * @var integer
 *
 * @ORM\Column(name="recid", type="integer")
 * @ORM\Id
 */
private $recid;

就是答案。