मुझे पता चला है कि सिद्धांत सरणी प्रकार serialize/unserialize का उपयोग कर रहे हैं और टेक्स्ट, पूर्णांक जैसे "सरल" फ़ील्ड के अंदर डेटा स्टोर कर रहे हैं।सिद्धांत और पोस्टग्रेस सरणी
लेकिन मेरे पास कुछ फ़ील्ड के साथ एक पोस्टग्रेज़ डेटाबेस है जिसमें सरणी (मुख्य रूप से टेक्स्ट) है। मैं उस डेटाबेस का उपयोग सिद्धांत के साथ करना चाहता हूं। क्या इसे संभालने का कोई तरीका है?
धन्यवाद
संपादित करें:
पुनश्च: अब मैं, पता क्रेग रिंगर के लिए धन्यवाद एसक्यूएल सरणियों एक अच्छा अभ्यास हो सकता है।
शायद मैं एक कस्टम प्रकार बना सकता हूं। क्या कोई ऐसा है जो पहले से ही बना है?
संपादित करें 2:
समस्या आधा हल:
<?php
namespace mysite\MyBundle\Types;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;
/**
* My custom postgres text array datatype.
*/
class TEXTARRAY extends Type
{
const TEXTARRAY = 'textarray'; // modify to match your type name
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return $platform->getDoctrineTypeMapping('TEXTARRAY');
}
public function convertToPHPValue($value, AbstractPlatform $platform)
{
// This is executed when the value is read from the database. Make your conversions here, optionally using the $platform.
return explode('","', trim($value, '{""}'));
}
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
// This is executed when the value is written to the database. Make your conversions here, optionally using the $platform.
settype($value, 'array'); // can be called with a scalar or array
$result = array();
foreach ($set as $t) {
if (is_array($t)) {
$result[] = to_pg_array($t);
} else {
$t = str_replace('"', '\\"', $t); // escape double quote
if (! is_numeric($t)) // quote only non-numeric values
$t = '"' . $t . '"';
$result[] = $t;
}
}
return '{' . implode(",", $result) . '}'; // format
}
public function getName()
{
return self::TEXTARRAY; // modify to match your constant name
}
}
और नियंत्रक
<?php
namespace mysite\MyBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Doctrine\ORM\EntityManager;
use Doctrine\DBAL\Types\Type;
class mysiteMyBundle extends Bundle
{
public function boot() {
Type::addType('textarray', 'mysite\MyBundle\Types\TextArray');
$em = $this->container->get('doctrine.orm.default_entity_manager');
$conn = $em->getConnection();
$conn->getDatabasePlatform()->registerDoctrineTypeMapping('TEXTARRAY', 'textarray');
}
}
मैं जानता हूँ कि 'myword' = किसी भी तरह के प्रश्नों के साथ इन सरणियों के अंदर खोज करना चाहते हैं (myarrayfield) ... क्या कोई सुराग है? # Doctrine2 चैनल पर
किसी ने मेरी बताया एक कस्टम DQL समारोह के निर्माण के लिए है, तो यहाँ यह है:
<?php
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
class ANY extends FunctionNode {
public $field;
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) {
return 'ANY(' .
$this->field->dispatch($sqlWalker) . ')';
}
public function parse(\Doctrine\ORM\Query\Parser $parser) {
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$this->field = $parser->StringPrimary();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
}
लेकिन, मुझे
$arr[] = $qb->expr()->like($alias.".".$field, $qb->expr()->literal('%'.trim($val).'%'));
की तरह एक प्रश्न बिल्डर के साथ अपने प्रश्नों का निर्माण, सरणी युक्त चीजों के साथ
और
if(count($arr) > 0) $qb->Where(new Expr\Orx($arr));
else unset($arr);
तो, कैसे मेरे समारोह का उपयोग करने के साथ वहाँ मिलती है? : \
एसक्यूएल सरणी वास्तव में एक * वास्तव में * आसान denormalisation हैं जो समझदारी से और सावधानी से उपयोग किया जाता है जब एक बड़ा प्रदर्शन बढ़ावा हो सकता है। उन्हें अच्छे कारणों से उपयोग नहीं किया जाना चाहिए, कम पोर्टेबल आदि हैं। –