Thread View: pl.comp.lang.php
1 messages
1 total messages
Started by Hoozar
Tue, 09 Sep 2014 11:16
Doctrine2 + ZF2 + collation + maksymalny wnerw
Author: Hoozar
Date: Tue, 09 Sep 2014 11:16
Date: Tue, 09 Sep 2014 11:16
115 lines
4119 bytes
4119 bytes
Witam!
Sprawa ma się tak:
Doctrine skonfigurowany tak:
'doctrine' => array(
'connection' => array(
'orm_default' => array(
'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
'params' => array(
'host' => '127.0.0.1',
'port' => 3306,
'user' => '***',
'password' => '***',
'dbname' => '***',
'charset' => 'UTF8',
),
),
),
),
tabele robione z annotation poleceniem vendor/bin/doctrine-module
orm:schema-tool:update
Tabela wygląda tak:
/**
* @ORM\Entity
* @ORM\Table( name="tabela1", options={"collate"="utf8_general_ci",
"charset"="utf8"})
*/
class PierwszaTabela
{
/**
* @ORM\Id
* @ORM\Column(type="string", nullable=false, length=31,
options={"collate"="utf_general_ci", "charset"="utf8"})
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="fq\cn\PierwszaTabela")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id",
nullable=true)
*/
protected $parent;
/**
* @ORM\Column(type="text", nullable=false)
*/
protected $nazwa = '';
ciach(...);
Jest druga tabela i relacja many-to-many:
/**
* @ORM\Entity
* @ORM\Table( name="tabela2", options={"collate"="utf8_general_ci",
"charset"="utf8"})
*/
class DrugaTabela
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
ciach(...)
/**
* @ORM\ManyToMany(targetEntity="fq\cn\PierwszaTabela")
* @ORM\JoinTable(name="tabela_join",
* joinColumns={@ORM\JoinColumn(name="drugatabela_id",
referencedColumnName="id")},
*
inverseJoinColumns={@ORM\JoinColumn(name="pierwszatabela_id",
referencedColumnName="id")}
* )
* @var ArrayCollection
*/
protected $dane_z_pierwszej_tabeli;
ciach(...)
jest też PROBLEM, polegający na tym, że doctrine ma w nosie collation i
przy tworzeniu tabela_join używa utf8_unicode_ci:
CREATE TABLE tabela_join (drugatabela_id INT NOT NULL, pierwszatabela_id
VARCHAR(31) NOT NULL, INDEX IDX_7987DA4E853CD175 (drugatabela_id), INDEX
IDX_7987DA4E578D5E91 (pierwszatabela_id), PRIMARY KEY(drugatabela_id,
pierwszatabela_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci
ENGINE = InnoDB;
a potem jeszcze:
ALTER TABLE tabela_join ADD CONSTRAINT FK_7987DA4E853CD175 FOREIGN KEY
(drugatabela_id) REFERENCES tabela2 (id); - to przejdzie
ALTER TABLE tabela_join ADD CONSTRAINT FK_7987DA4E578D5E91 FOREIGN KEY
(pierwszatabela_id) REFERENCES tabela1 (id); - a to oczywiście wywali
błąd, bo ma rozne collation.
W dokumentacji do Doctrine stoi niestety ze:
## Creating MySQL Tables now defaults to UTF-8
If you are creating a new MySQL Table through the Doctrine API,
charset/collate are
now set to 'utf8'/'utf8_unicode_ci' by default. Previously the MySQL
server defaults were used.
Czy jest znany jakiś sposób na eleganckie obejście tego, czy zostaje
tylko poprawienie źródeł Doctrine?
Pozdrawiam (ale nie twórców tego konkretnego fragmentu w Doctrine)
Huzar
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads