Doctrine isn't working After version upgrade - php

I do generate entities from database. Here is a file that I generated before updating to new version of doctrine and with the latest version of doctrine:
http://pastebin.com/g8DsUjmm
You will see, it adds an extra 'ORM' in annotations on new ones.
I am now having problem(Exception) while executing doctrine code which says:
Class GdCities does not exist and could not be loaded /my_path/application/third_party/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php
Anyone have any idea, why this is happening. before updating, with old entities and doctrine version, it was working fine.

I did get this resolved by removing the "ORM\" part from all entities' table and column name. Not sure, if its a doctrine bug or I am doing something in different way.

Related

Doctrine MongoDB ODM does not persist

I'm trying to start using MongoDB with Doctrine MongoDB ODM 1.1.3 and Laravel 5.4. Everything had been going fine before I removed the database called "doctrine" manually (the default database name I guess) in order to clean up the rubbish in it, so basically I just wanted to remove the database and was hoping that Doctrine will create a new one. Now when I'm trying to call
$mgr->persist($divRoot);
$mgr->flush();
It assigns an ID to the $divRoot object, but doesn't persist it. I.e. when I then call the findAll() method on the repo, it returns nothing. And it doesn't create any databases anymore. The $divRoot has changing fields every time I'm trying to save it. I've got really stuck, please help
UPDATE 1
If I initialize a new DocumentManager specifying a new path to the documents (AnnotationDriver::create($documents)), the ODM works normally persisting and retrieving the documents.
I've figured out what was wrong. I was working only with embedded documents whereas it must be at least one root Document. Originally all of them were marked as Documents that's why I was able to persist them, it's nothing to do with the database removal.
So, I was trying to persist a composite consisting out EmbeddedDocuments only.
The solution was to create a root wrapper for the composite marked as Document.

Symfony2: Doctrine extension Softdeleteable is permanently deleting Translatable elements

I'm using the latest version dev-master of Doctrine extensions with Symfony2.7.0.
I added both extensions Softdeleteable and Translatable to my entity. The problem is that when the entity gets soft-deleted its translation gets hard-deleted.
Is there a workaround this?
Edit
I have found this issue on Github, but I can't make much of the answer.
After reviewing the github issues and the proposed "fixes" and consulting experts I have decided that this was more trouble than its worth.
The problem is obviously the listner, and I shouldn't be messing with the bundles under vendor.
When translatables get the 'delete' from my soft-deleted object, these "children" of my object are not really objects of their own thus can't be configured to be soft-deleted.
My solution is to add a deletedAt attribute, NULL by default and when in my controller I used to execute $entityManager->delete($object) I now, just have to change the value of deletedAt to the current DateTime. $object->setDeletedAt($date).
And when retrieving objects I just add a clause SELECT * FROM table_name WHERE deletedAt IS NULL;
This implies changing a lot of queries but it is the simplest option while waiting for a fix.

Importing database structures in Symfony

As I said many times I'm new in Symfony2 framework and I ask about it a lot. Here is my new problem. I'm trying to import my mysql database into my symfony application. I'm following this tutorial http://www.sitepoint.com/building-a-web-app-with-symfony-2-bootstrapping/
This is the code that I run;
php app\console doctrine:mapping:import
This is the error that I get;
[DoctrineORMMappingMappingException] Property "bookid" in "BookHeadline" was already declared, but it must be declared only once
In the link there is a comment about this issue and it says remove the FK 'bookid'. I tried it but even the sql query did not work. Also this is the sql query.
Can you paste the table structure for that entity?
Also take a look at Symfony2 docs about importing your database

Deleted table appears while generating entities (using doctrine) in symfony 2

I had a table "user" and later i renamed this to "Users", but while generating entities with doctrine: generate entities command, the deleted table always appears. Surprisingly, the same table is not appearing among in doctrine orm.xml files list.
I had removed all orm.xml files, entities files, cleared cache and tried again, but still the same error appears.
It will be really helpful if someone can guide me since im a beginner in doctrine.
Thanks and regards,
Tismon Varghese

Doctrine [Semantical Error] Error: Class xxx has no field or association named yyy

For last few days I'm experiencing following issue with doctrine - since I am not allowed to paste any source code, I'll try to describe briefly:
I am using doctrine orm and I need to add a new column to an existing table in DB - mapping between DB and entities is done via xml mapping file - here are the steps I've proceeded:
I've added into the entity file - let's call it Entity.php - new field for that newColumn
I've added info about this newColumn into the XML mapping file as new XML element 'field'
I've executed doctrine command to change the schema of the DB based on edited mapping file
I've updated the query in EntityRepository.php file to include this new column.
When I then run the application, I am still getting this error:
[Semantical Error] Error: Class Entity.php has no field or association named newColumn
So, if I am understanding this properly, it is saying that in the Entity.php is not field newColumn to which should be the new DB column mapped.
But that is not the case, since it was the very first step I've done.
I've already tried this:
Checked there is no typo in name of the newColumn across all files
Checked the field in Entity.php has proper access modifiers - i.e. it is not private
Cache was cleared for the case that some bad version of Entity.php was stored
I've restarted apache server which the application runs on
Check your metadata cache. If you're using some external caching mechanism (like Memcached or xcache) it's probably shared across your vhosts. If one vhost populates the cache with its own mapping metadata (after apache restart), second vhost just uses it and doesn't care about different .dcm.xml mappings.
If it's your development server/vhost, it's usually much better to disable ORM caching at all (config/autoload/database.local.php).
Maybe my problem and solution would help somebody.
/* *
* #ORM\Column(name="user_id")
*/
protected $userId;
No, there was no typo in variable name. Access is correct and everything looked to be fine.
Some of you probably already see the problem.
Yes. It's /* * instead of /**. I took me about hour to find it :]
What was strange - it was working in join, but not when I have used it in where.
run this command
php bin/console doctrine:cache:clear-metadata on both APP_ENV=prod and APP_ENV=dev
Have the same problem. The solution was to replace in query condition like
LOWER(l.bank_title) LIKE :search
with its camelCase variant:
LOWER(l.bankTitle) LIKE :search

Categories