I have a table defined by:
Modification:
columns:
id:
type: integer
primary: true
autoincrement: true
name: string
author: string
attributes:
export: all
When I run this code:
$tbl = new Doctrine_Table(
'Modifications',
Doctrine_Manager::getInstance()
->getCurrentConnection()
);
$tbl->findOneBy('name', 'yacoby');
I get this error:
Doctrine_Table_Exception: Invalid expression found: ()n()a()m()e()
/home/yacoby/documents/dev/netbeans/php/Doctrine/Table.php:2741
/home/yacoby/documents/dev/netbeans/php/Doctrine/Table.php:1707
/home/yacoby/documents/dev/netbeans/ESSearch/test/library/Search/Table/ModsTest.php:21
Does anyone have any idea why and what I can do to fix it?
Try deleting the 's' after "Modification"...
If that doesn't have any affect, you may want to check that the table has been constructed properly by calling something like the method Doctrine_Table::getColumns and checking the output (i.e. that the array contains the columns you defined).
If it isn't what you expect, check that the files that the models are defined in have been loaded properly.
If the table has been set up already somehow, the correct way to get it is like this:
$tbl = Doctrine::getTable($what);
I ran into the same error while trying to construct (while I should have been getting) the Doctrine_Table of the $what entity to run som magic find functions on it.
Related
When I do $user = \App\Models\User::findOrFail(512) in php artisan tinker I get something like this back:
=> App\Models\User {#4586
userID: 512,
userName: "neubert",
legalFirst: "Neu",
firstName: "Neu",
lastName: "Bert",
...
}
Notably, has_ability_to_view_users_timeclock_reports is not present in what's returned. And yet when I do $user->has_ability_to_view_users_timeclock_reports I got a non-null value back (I get true back).
My question is... how might I found out where has_ability_to_view_users_timeclock_reports is defined? It's not defined in the App\Models\User model. When I do grep -r has_ability_to_view_users_timeclock_reports . in the code base I see it being used but never actually defined.
It's not a column in the table that \App\Models\User corresponds to.
Any ideas?
The output for models in tinker is determined here https://github.com/laravel/tinker/blob/97357b4ebec94d728847bff80362a4eb9f64ede0/src/TinkerCaster.php#L103
You can dd() your model to see more info
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 have an entity that is related to some other entities.
On the end, I have an object like tat:
paper.submission.authors
For some of the paper.submission, there is no author, and in my twig template, I am doing:
{% for author in paper.submission.authors}
do something
{% endfor %}
And for the paper.submission with no authors, I am getting "Entity was not found" exception.
Is thee any possibility to test if the object exists before my for loop.
I have try the is defined, it is always true. Then, I have tryed is not null, but this is also generating the exception.
Thank you very much in advance.
Problem
Doctrine throws this Exception when it doesn't find the related entity. It seems redundant to say this, but in fact this is important.
It means it could find an ID related to it, but the request doctrine made didn't match any result.
My guess is that your database table (link table actually) submission.authors contains IDs of 0 instead of NULL.
With such, Doctrine thinks there IS an author with ID of 0, and therefor, cannot find it.
What happens
submission.authors always exists. It is an Uninitialized Doctrine Proxy.
var_dump($submission->getAuthors());
Would show you what contains exactly submission.authors
At this point, no queries are made. It simply returns a PersistentCollection with a flag isInitialized to false.
The exception occurs when you're trying to get a property out of it
foreach ($submission->getAuthors() as $author) {
}
When doing this doctrine will check if getAuthors is initialized. If not, it will run the following query
SELECT <stuffs> FROM authors WHERE id = 0;
Which returns no match and will throw an EntityNotFound Exception
Fix
You must set your id row's default to NULL and make a query to update all 0's to NULL.
With this, you can easily test submission.authors with is not null
Doctrine will not run any query if it finds a NULL
How to debug to find which related entity was not found?
Exception message improved in repository https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Proxy/ProxyFactory.php#L160 but if you use older version you can do the following debugging.
If you use older version
Put following code to ProxyFactory class before throw new EntityNotFoundException(); line vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php:177
$entity = $classMetadata->getReflectionClass()->getShortName();
$id = $classMetadata->getIdentifierValues($proxy)['id'];
var_dump("$entity WHERE id = $id NOT FOUND.");exit;
throw new EntityNotFoundException();
In your entity you can made something like this:
public function getSubmission(){
if($this->Submission->getId()==0) return null;
return $this->Submission;
}
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 :)