Article View: pl.comp.lang.php
Article #230549ZF2 + Doctrine + collation = porazka
From: Hoozar
Date: Tue, 09 Sep 2014 11:20
Date: Tue, 09 Sep 2014 11:20
115 lines
4051 bytes
4051 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
Huzar
Technical Details
Message-ID:
<lumnq1$la$2@usenet.news.interia.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.interia.pl!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.interia.pl!not-for-mail From: Hoozar <hoozar@interia.pl> Newsgroups: pl.comp.lang.php Subject: ZF2 + Doctrine + collation = porazka Date: Tue, 09 Sep 2014 13:20:34 +0200 Organization: INTERIA.PL S.A. Lines: 115 Message-ID: <lumnq1$la$2@usenet.news.interia.pl> NNTP-Posting-Host: 188.123.220.84 Mime-Version: 1.0 X-Trace: usenet.news.interia.pl 1410261633 682 188.123.220.84 (9 Sep 2014 11:20:33 GMT) X-Complaints-To: usenet@firma.interia.pl NNTP-Posting-Date: Tue, 9 Sep 2014 11:20:33 +0000 (UTC) User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit