Doctrine turns my column names into all lower case to improve compatibility. How do I prevent this from happening?
users:
actAs: [Timestampable]
columns:
userId:
type: integer
length: 4
primary: true
autoincrement: true
or
$this->hasColumn('userId', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'primary' => true,
'autoincrement' => true,
));
then becomes
userid
This is a problem because I have lots of existing code and data that uses the camelCase convention. Is there some sort of easy boolean I can change to make it keep my columns exactly as written?
The Yaml conversion is where the issue lies. To fix this you need to alias the column name in the YAML schema file IE: name: user_id as userId
Related
I'm trying to validate a form in a symfony 2.3 project,
So I have a 'Customer' field :
$builder
->add('customer',
'entity',
array('property'=> 'item',
'multiple' => true,
'expanded' => true,
'class' => 'OrdersBundle:Customer',
'required' => true, 'empty_value' => '',
'query_builder' => function(\Ella\OrdersBundle\Repository\CustomerRepository $er) {
return $er->createQueryBuilder('q')->andWhere("q.is_delete = 0")->orderBy('q.item', 'asc');
}));
I'm trying to return an error when user didn't select anything, so i do this :
properties:
customer:
- Choice: { min: 1, minMessage: 'message' }
Or
properties:
customer:
- NotBlank:
message: message
and other things, but nothing works , an idea of what I'm doing wrong ??
In the doc they say we could use an array, but this doesn't work either ...
Actually Symfony return :
Either "choices" or "callback" must be specified on constraint Choice
For the Choice validator you either need to specify an array with the available allowed choices or a callback function, from the docs:
This constraint is used to ensure that the given value is one of a given set of valid choices. It can also be used to validate that each item in an array of items is one of those valid choices.
What you could use may be the Count validator:
customer:
- Count:
min: 1
max: 99
minMessage: "Min message"
maxMessage: "You cannot specify more than {{ limit }}"
I have a weird problem.
Here's my yaml:
Request:
actAs: { Timestampable: ~ }
columns:
id: { type: integer(4), primary: true, autoincrement: true, notnull: true }
When i perform a symfony doctrine:build --all --no-confirmation inside my BaseRequest.class.php there's an error during the declaration of my id field:
$this->hasColumn('id', 'integer', 4, array(
'type' => 'integer',
'primary' => true,
'autoincrement' => true,
'length' => 4,
));
As you can see it should be auto_increment but instead it's autoincrement so i have to manually change this after each build.
Is there any way to fix this ?
not exactly answer to your question, but you don't need to specify id column for your entities, doctrine does that automatically
Is it possible to have multiple slugs on one table in Doctrine?
I tried this in my yaml-file:
Article:
tableName: tst_article
actAs:
Sluggable:
unique: true
fields: [title]
canUpdate: true
Sluggable:
unique: true
fields: [text]
name: secondSlug
columns:
id:
type: integer(8)
primary: true
autoincrement: true
category_id:
type: integer(8)
title:
type: text(255)
text:
type: clob
But after generating the sql only the secondSlug was generated...
It is possible. In your table definition write:
public function setUp() {
parent::setUp();
$sluggable0 = new Doctrine_Template_Sluggable(array(
'fields' => array(0 => 'name'),
'unique' => true,
'canUpdate' => true
));
$this->actAs($sluggable0);
$sluggable1 = new Doctrine_Template_Sluggable(array(
'fields' => array(0 => 'native_name'),
'unique' => false,
'canUpdate' => false,
'name' => 'native_name_slug'
));
$this->actAs($sluggable1);
}
The problem is in YAML itself. You have something like this:
keyA:
keyB: value
keyB: value
What might be translated into:
array(
'keyA' => array(
'keyB' => 'value',
'keyB' => 'value'
)
);
So as you see there is definition of keyB and then keyB is overwritten with new value. So in your YAML file second definition overrides the first one.
How to solve that? I don't know, but I'll do some researches. Right now you're forced to declare your models in pure PHP.
Article:
tableName: tst_article
actAs:
Sluggable:
unique: true
fields: [title, text]
canUpdate: true
columns:
id:
type: integer(8)
primary: true
autoincrement: true
category_id:
type: integer(8)
title:
type: text(255)
text:
type: clob
Although changing libraries is not recommended, sometimes it's a necessary evil. A very small change allows you to declare Sluggable_1, Sluggable_2, etc. in your YAML.
--- a/lib/vendor/doctrine/Doctrine/Import/Builder.php
+++ b/lib/vendor/doctrine/Doctrine/Import/Builder.php
## -711,8 +711,10 ## class Doctrine_Import_Builder extends Doctrine_Builder
{
// find class matching $name
$classname = $name;
- if (class_exists("Doctrine_Template_$name", true)) {
- $classname = "Doctrine_Template_$name";
+ // HACK to allow multiple Sluggables
+ $classname = preg_replace('/_[0-9]+$/', '', $classname);
+ if (class_exists("Doctrine_Template_$classname", true)) {
+ $classname = "Doctrine_Template_$classname";
}
return " \$" . strtolower($name) . "$level = new $classname($option);". PHP_EOL;
}
the players:
64bit linux with
php 5 (ZendFramework 1.10.2)
PostgreSQL 8.3
Doctrine 1.2
Via a Flash/Flex client i get an 8byte integer value.
the field in the database is an BIGINT (8 byte)
PHP_INT_SIZE show that system supports 8byte integer.
printing out the value in the code as it is and as intval() leads to this:
Plain: 1269452776100
intval: 1269452776099
float rounding failure ?
but what really driving me nuts is
ERROR: invalid input syntax for integer: "1269452776099.000000"'
when i try to use it in a query. like:
Doctrine_Core::getTable('table')->findBy('external_id',$external_id);
or
Doctrine_Core::getTable('table')->findBy('external_id',intval($external_id));
How i am supposed to handle this ? or how can i give doctrine a floating point number which it should use on a bigint field ?
Any help is much appreciated!
TIA
EDIT:
from the model:
$this->hasColumn('external_id', 'integer', 8, array(
'type' => 'integer',
'length' => 8,
'fixed' => false,
'unsigned' => false,
'notnull' => false,
'primary' => false,
));
Database field is bigint 8 bytes.
EDIT2:
http://bugs.php.net/bug.php?id=48924 seems to be the root of the problem
As you have already mentioned, you hit this bug.
To work around it, pass the parameter as a string and make sure it's converted to a BIGINT on the database side:
$q = Doctrine_Query::create();
$q->from('table AS t')
->where("t.external_id = CAST(:external_id AS BIGINT)", array(':external_id' => $external_id))
->limit(1);
$result = $q->execute();
I'm using Doctrine for database abstraction. Now I'd like to get the auto_increment primary key from the freshly-created (and save()'d) object - but $obj->toArray() shows me that the field is empty after calling save().
Is there a flag that I'm not aware of that does this? Or do I really have to query the object from the database?
Ensure that you have the autoincrement flag set when setting up your object in the setTableDefinition() method (or related YAML config file). If this flag isn't set, then Doctrine won't know to update it. You should have something that looks like this:
$this->hasColumn('id', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => true,
'primary' => true,
'autoincrement' => true //this flag right here
)
);
Call refresh on the record instance before the toArray.