Symfony 1.4 and doctrine autoincrement instead of auto_increment - php

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

Related

Validation Symfony2 Entity Choice Field

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 }}"

drop down problems using symfony

i am new in symfony,its has been two days i have stacked on a problems making drop downs using symfony froms relations based on schema.yml
schema.yml is
FieldsCategory:
tableName: fld_category
columns:
id:
name: id as FieldsId
type: integer(10)
primary: true
autoincrement: true
category_name:
name: category_name as CategoryName
type: string
default: ''
notnull: true
relations:
FieldsCategory:
class: FieldsCategory
foreignAlias: Fields
local: id
foreign: fields_category_id
Fields:
tableName: fld_fields
columns:
id:
name: id as FieldsId
type: integer(10)
primary: true
autoincrement: true
fields_name:
name: fields_name as FieldsName
type: string
default: ''
notnull: true
fields_desc:
name: fields_desc as FieldsDescription
type: string
default: ''
notnull: true
amount:
name: amount as TotalAmount
type: integer
notnull: true
fields_type_id:
name: fields_type_id as FieldsTypeId
type: integer
fields_category_id:
name: fields_category_id as FieldsCategoryId
type: integer
and my forms is
$this->setWidgets(array(
'FieldsId' => new sfWidgetFormInputHidden(),
'fields_type_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Fields'), 'add_empty' => false)),
'FieldsName' => new sfWidgetFormTextarea(),
));
$this->setValidators(array(
'FieldsId' => new sfValidatorChoice(array('choices' => array($this->getObject()->get('FieldsId')), 'empty_value' => $this->getObject()->get('FieldsId'), 'required' => false)),
'fields_type_id' => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Fields'), 'required' => false)),
'FieldsName' => new sfValidatorString(array('required' => false)),
));
its given me this error
i have tried all possible ways but i couldnt solve this problems/
and help will be approciated in advance

Doctrine case sensitivity in schema.yml

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

Can a table have multiple slugs in Doctrine?

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;
}

Make doctrine load auto_increment value after save

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.

Categories