This is the stage:
Linux debian with Symfony2.5.6/Doctrine2 connected to Sql Server via (FreeTDS DB-lib).
intellectsoft-uk/MssqlBundle Driver installed and running ok.
Two SQL Server related tables with spaces
in Table/Field names (sorry, i can't post images):
´
dbo.MYCOMPANY$Item
No. - varchar(32)
Description - varchar(32)
dbo.[MYCOMPANY$Item Variant]
Code - varchar(32)
Item No. - varchar(32)
´
Note: Yes... it's a horrible naming style, Dynamics Nav and microsoft are the offenders.
Two Doctrine's entities mapping this tables with a OneToMany
relation pointing to Item Variant
entity from Item
entity:
/**
* @ORM\Table(name="dbo.MYCOMPANY$Item")
* @ORM\Entity
*/
class Item
{
/* @ORM\Id
* @ORM\Column(name="[No_]", type="string", length=32)
*/
private $no;
/**
* @ORM\Column(name="Description", type="string", length=128)
*/
private $description;
/* @ORM\OneToMany(
* targetEntity="DymamicsBundle\Entity\ItemVariant",
* mappedBy="item", cascade={"persist","remove"})
*/
private $itemVariants;
}
/**
* @ORM\Table(name="dbo.[MYCOMPANY$Item Variant]")
* @ORM\Entity
*/
class ItemVariant
{
/* @ORM\Id
* @ORM\Column(name="Code", type="string", length=32, nullable=false)
*/
private $code;
/**
* @ORM\Id
* @ORM\ManyToOne(
* targetEntity="DymamicsBundle\Entity\Item",
* inversedBy="itemVariants")
* @ORM\JoinColumn(
* name="[Item No_]",
* referencedColumnName="[No_]", onDelete="CASCADE")
*/
private $item;
}
In a controller i query for an item XXXXXX:
/** @Template() */
public function helloAction($name)
{
$item = $em->getRepository("DynamicsBundle:Item")->findByNo('XXXXXX');
return array('item' => $item);
}
In the index.html.twig
template i print the fields without problems:
{% block content %}
{{ item.no }}
{{ item.description }}
{% endblock %}
... And now the problem:
If i try to access to the member itemVariants
...
{% block content %}
{{ item.no }}
{{ item.description }}
This item has {{ item.itemVariants.count }} variants
{% for v in item.itemVariants %}
<p>{{ v.code }}</p>
{% endfor %}
{% endblock %}
I get this fatal error:
>
> An exception has been thrown during the rendering of a template
> ("Unrecognized field: t0.[Item No_]") in
> .../DynamicsBundle/Resources/views/Demo/index.html.twig at line 2.
>
One tested solution (non-viable for me, since i can't modify Dynamics Nav database fields):
Renaming the Item No.
field in the table dbo.[MYCOMPANY$Item Variant]
by... i.e. ItemNo
... problem resolved:
class ItemVariant
{
...
* @ORM\JoinColumn(
* name="ItemNo",
...
private $item;
}
The output:
This item has 2 variants
red
blue
Accordingly... the problem seems to be the Item No.
field name
I tried to change this parameters in the SQL Server database:
ANSI_NULLS ON
ANSI_PADDING ON
ANSI_WARNINGS ON
ARITHABORT ON
QUOTED_IDENTIFIER ON
CONCAT_NULL_YIELDS_NULL ON
NUMERIC_ROUNDABORT OFF
... but nothing
¿Any suggestion? Thx...