For some reason, my generated pages are using for the field name article_id instead of articleid as it is in my database and model. I have tried running "symfony doctrine:build --all" and "symfony doctrine:generate-module ..." multiple times to no avail.
Here is an example of a bad generated file:
./apps/frontend/modules/article/templates/_form.php: <?php echo link_to('Delete', 'article/delete?article_id='.$form->getObject()->getArticleId()
Any suggestions would be greatly appreciated!
Thanks in advance!
EDIT
I tried cleaning as recommended, I also tried deleting the module and rebuilding it.
EDIT 2
After running "symfony doctrine:build --all" I do see this as a reference to the yml file used:
>> file+ /tmp/doctrine_schema_97369.yml
Here is the Article section from the /tmp yml file:
Article:
columns:
ArticleID:
type: integer
primary: true
autoincrement: true
length: '4'
It is possible that if you changed this name in your schema, that the old model files have kept the old name. You can try to clean your model files using the task doctrine:clean-model-files
Related
I am using the following orm description:
App\Entity\Journal:
type: entity
table: hpa_journal
repositoryClass: App\Repository\JournalRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
longDescription:
type: array
nullable: true
column: long_description
When I run a doctrine:schema:create it has no problems at all and creates the DB.
But, when I run a schema:update I get the following error:
php bin/console doctrine:schema:update --dump-sql
The following SQL statements will be executed:
ALTER TABLE HPA_JOURNAL MODIFY (long_description CLOB DEFAULT NULL);
Which makes no sense since the CLOB is already as DEFAULT NULL, doctrine made it that way with the schema:create
When I run the schema:update --force to get rid of the message, I get the ORACLE error:
ORA-22859: invalid modification of columns
When doctrine compares the DB and the model it triggers a problem since in the DB the types "text", "array", "json_array",... are just CLOBS.
In order to really make the difference you must add (if not made automatically like in my case) a proper comment:
COMMENT ON COLUMN HPA_JOURNAL.LONG_DESCRIPTION IS '(DC2Type:array)'
I'm working on a symfony 1.4 project which uses Doctrine 1.2. I want to add some custom property for fields inside my schema.yml. The purpose of this is to reuse schema.yml in some other place other than Doctrine, to maintain some meta data about the entity. I tried to add a customproperty as I shown in bellow sample.
TestEntity:
tableName: test_table
columns:
id:
type: integer(4)
primary: true
autoincrement: true
name:
type: string(200)
customproperty: true
But when I tried to do doctrine build model, now it fails giving the error as follows.
"Invalid schema element named "customproperty" at path "TestEntity->columns->name""
I checked the schema.php file in following location to debug the error.
symfony/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Import/Schema.php
This error comes because the custom property we are specifying is not there in "$_validation" array. Once I added the "customproperty" into that array it stopped giving the error.
But what I did was a hack to doctrine library and is there any other better way to achieve this without touching the library files.
I've just started working with Propel and I love it, but I have a question regarding how to utilize multiple database connections. I know I can set stuff up in my schema to connect to multiple different databases, but I'm curious how to handle this in code.
The issue I have is multiple databases, and each of them has slightly different schemas with no data warehousing. As a result I have things resembling the following:
databaseName: westCoastUsers
table: users
column1: email
column2: password
column3: FirstName
databaseName: eastCoastUsers
table: users
column1: email
column2: password
column3: firstName
column4: lastName
Right now in PHP non-Propel version, I'm doing all this by hand, and switching databases manually as required. I'm hoping to streamline things a bit, and I'm curious how to model this. Is there a way I can just have something like eastCoastUser and westCoastUser models that each refer to the proper database/etc or am I trying to wedge in something not supported?
I read this: How to use two database in propel but am uncertain how to actually execute that in code.
Thanks for the help
In your schema files, you can provide a name for the class that represents your table. They do not have to use the same name as the table. You do this with the phpName attribute on the table element.
For example your schema.xml could contain something like this
<database name="westCoastUsers">
<table name="users" phpName="WestCoastUser">
...columns here...
</table>
...
</database>
<database name="eastCoastUsers">
<table name="users" phpName="EastCoastUser">
...columns here...
</table>
</database>
(edit, note that the name="westCoastUser" on the database element refers to the name of the database, not the classes with similar names)
Then at build time, propel will generate WestCoastUser, WestCoastUserQuery, WestCoastUserPeer, EastCoastUser, EastCoastUserQuery and, EastCoastUserPeer. Each class will connect using the database it was defined under in your schema.
I wrote this originally for symfony 1.2, but I believe it all applies.
I’m using Symfony 1.2.4 for this example.I have two databases, master and slave
If you are going to use multiple databases, there are a few things that you are going to need to do.
You will need separate schema files for both (master.schema.yml and slave.schema.yml)
To use build-sql and insert-sql, you will need multiple propel.ini files
You will need to add an attribute to your schema files to get them to build right
Step 1
Create the databases.yml with two separate connections:
dev:
propel:
param:
classname: DebugPDO
test:
propel:
param:
classname: DebugPDO
all:
propel:
class: sfPropelDatabase
param:
classname: PropelPDO
dsn: mysql:dbname=master;host=xxx.xxx.xxx.xxx
username: uname
password: pass
encoding: utf8
persistent: true
pooling: true
master:
class: sfPropelDatabase
param:
classname: PropelPDO
dsn: mysql:dbname=slave;host=xxx.xxx.xxx.xxx
username: uname
password: pass
encoding: utf8
persistent: true
pooling: true
Step 2
As mentioned you will need two schema files. Please notice that you will need to define a package attribute for the database that matches up to the tables, and in this case it is ‘lib.model.master’ for the master connection.
master.schema.yml
master:
_attributes:
package: lib.model.master
defaultIdMethod: native
my_table:
_attributes: { package: lib.model.master }
my_id: { type: INTEGER, size: '11', primaryKey: true, autoIncrement: true, required: true }
etc.....
slave.schema.yml
slave:
_attributes:
package: lib.model.slave
defaultIdMethod: native
auctionp:
_attributes: { package: lib.model.slave }
etc.....
Step 3
You will need to create separate propel.ini files. In this example I used propel-master.ini and propel-slave.ini. Each of these files need to be configured for their respective databases.
Step 4
You will need a good batch file to build your your databases using the propel tools. Mine looks like this:
From the application root:
symfony build-model; cp config/slave-propel.ini config/propel.ini; symfony propel:build-sql; symfony propel:insert-sql --no-confirmation; cp config/propel-master.ini config/propel.ini; symfony propel:build-sql; symfony propel:insert-sql --no-confirmation;
Step 5
You will need to clean out /lib/model if you already built your model using one database and are now doing a split. Deleting the files in the “map” and “om” directories and the root directory will help you avoid conflicts.
Step 6
To use the two databases in code, you will need to add a bit to the connection, like the following:
Example 1:
$object = self::doSelect($c, Propel::getConnection('master'));
Example 2:
$newObject->save(Propel::getConnection('slave'));
Example 3:
$con = Propel::getConnection("propel");
$sql = "ALTER TABLE runlinhp CHANGE class class_rat varchar(15)";
$stmt = $con->prepare($sql);
$stmt->execute();
I'm using doctrine and trying to validate some models.
I have the following in my YAML schema:
User:
package: User
columns:
username:
type: string
notnull: true
notblank: true
minlength: 4
password:
type: string
notnull: true
If I create a new user, it always validates, regardless of what values I give it.
eg:
$testuser = new User();
$testuser->username = ' ';
if ( ! $testuser->isValid())
{
echo 'User is invalid!';
}
EDIT:
The above is just an example. It still validates even if values specified as NOT NULL in the schema are omitted.
The invalid method is never produced. Does anyone know what might be causing this?
Any advice appreciated.
Thanks.
the reason is: there's no isValid() function in your models which created by Doctrine. (in your models/generated/*.php)
Step 1.
refer to Doctrine Manual: you should put this in your bootstrap.php or any your php file header)
$manager->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_ALL);
Step 2.
rebuild your models' files.
Step 3.
it should work now :)
Currently developing an application using the newest version of symfony, obtained through PEAR. This is my exact schema configuration
propel:
user:
id:
name: { type: varchar(255), required: true }
level: { type: integer, required: true, default: 1 }
created_at:
post:
id:
title: { type: varchar(255), required: true }
post: { type: longvarchar, required: true }
user_id:
created_at:
updated_at:
comment:
id:
relation: integer
comment: { type: varchar(300), required: true }
nick: { type: varchar(100), required: true }
created_at:
updated_at:
The awake and aware of you have probably noticed that user_id in post is a foreign key to user. According to the definite guide; [quote title=Quote:](columns ending with _id are considered to be foreign keys, and the related table is automatically determined according to the first part of the column name).[/quote]
Whenever I try to build EITHER filters or FORMS (build-filters/build-forms/build-all) I get the follwing error message.
>> propel generating form classes
-----> Cannot fetch TableMap for undefined table: user. Make sure you have the static MapBuilder registration code after your peer stub class definition. <------
[?php
/**
* Post form base class.
*
* #package ##PROJECT_NAME##
* #subpackage form
* #author ##AUTHOR_NAME##
* #version SVN: $Id: sfPropelFormGeneratedTemplate.php 16976 2009-04-04 12:47:44Z fabien $
*/
class BasePostForm extends BaseFormPropel
{
public function setup()
{
$this->setWidgets(array(
'id' => new sfWidgetFormInputHidden(),
'title' => new sfWidgetFormInput(),
'post' => new sfWidgetFormTextarea(),
'user_id' => new sfWidgetFormPropelChoice(
I've also tried defining the foreignTable and foreignReference in my schema, but without luck. This is a fresh symfony-project, only created to debug this error. I've tried using singular and plural names for my tables. Am I doing something horribly wrong, or is this a solid bug? Appreciate ANY input, this is driving me crazy!
I have a forum thread over at symfony's official community, here: http://forum.symfony-project.org/index.php/m/77979/ - there's been some suggestions (like how I forgot to use a tilde and that "user" is a pre-defined class, but the problems remains SOLVED [edited] as of now.
One free internet hug, major props and a free space shuttle to the mighty soul who come up with a solution! (disclaimer: there's actually no free space shuttle)
Update: PROBLEM HAS BEEN SOLVED! ... after countless hours of back tracking and debugging.
The issue was caused by a TABLE prefix manually coded in in propel.ini like this:
; custom table prefix
propel.tablePrefix = mindmonkey_
There's no communication with schema.yml and the propel.ini or something like that, so everything bugged up. My conclusion from this is: forget prefixes, just use a dedicated schema for each project... I just used prefix as a habit, always done - but never again unless specifically instructed to do so!