doctrine

Doctrine2 fetching rows that have manyToMany association by QueryBuilder

余生颓废 提交于 2019-12-12 13:29:48
问题 everyone. I have 2 entities City and POI. Mapping looks like this: class City { /** * @ORM\ManyToMany(targetEntity="POI", mappedBy="cities") * @ORM\OrderBy({"position" = "ASC"}) */ protected $pois; and class POI { /** * @ORM\ManyToMany(targetEntity="City", inversedBy="pois") * @ORM\JoinTable(name="poi_cities") */ protected $cities; I would like to fetch all POIs that have at least 1 association with some City using QueryBuilder. I should probably use exists() function but I don't quiet know

No role detected by BjyAuthorize when login

无人久伴 提交于 2019-12-12 12:27:39
问题 I am working with ZF2, Doctrine ORM and BjyAuthorize. The problem is that when I got logged in the method getRoles of the identity returns empty. class User implements UserInterface, ProviderInterface{ /** * @var \Doctrine\Common\Collections\Collection * * @ORM\ManyToMany(targetEntity="Application\Entity\Role", inversedBy="user") * @ORM\JoinTable(name="user_role_linker", * joinColumns={ * @ORM\JoinColumn(name="user_id", referencedColumnName="user_id") * }, * inverseJoinColumns={ * @ORM

Symfony2 Doctrine entity not hydrated

梦想的初衷 提交于 2019-12-12 12:11:33
问题 I get an entity Member from the entity manager, did a var_dump, everything ok except for the manyToOne relation with Family , so I tried a var_dump($member->getFamily()); and surprisingly, the only correct value was the family's ID, all the other properties were null (which is not the case in the database...) Here is my Member stuff /** * @var Family * * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Family", inversedBy="members") * @ORM\JoinColumn(name="family_id", referencedColumnName="id")

Propel and leftJoin

自作多情 提交于 2019-12-12 12:08:36
问题 In Doctrine i can: $q = Doctrine_Query::create() ->from('One o') ->where('t.text = ?', 'aaa') ->andWhere('h.text = ?', 'bbb') ->leftJoin('o.Two t') ->leftJoin('t.Three h') ->leftJoin('h.Four f') ->execute(); How can i make this in Propel from Symfony 1? 回答1: If you use propel before 1.6 , you have to follow You have to know the primary key for each relation. If it's id , it can be something like that: $c = new Criteria(); $c->add(TwoPeer::TEXT, 'aaa'); $c->add(ThreePeer::TEXT, 'bbb'); $c-

How to drop a foreign key in doctrine 2 migrations

微笑、不失礼 提交于 2019-12-12 11:22:52
问题 I want to drop a foreign key in a doctrine 2 migration. But there is no dropForeignKeyConstraint() Does anybody know how to drop it? 回答1: public function down(Schema $schema) { $table = $schema->getTable('table_name'); $table->removeForeignKey('foreign_key_name'); } 回答2: Here it is: public function down() { $this->dropForeignKey('table_name', 'email_foreign_key'); } http://www.doctrine-project.org/projects/orm/1.2/docs/manual/migrations/en 来源: https://stackoverflow.com/questions/3643344/how

Symfony2 Container Aware Form Type

旧巷老猫 提交于 2019-12-12 11:03:50
问题 Is there a way to make a form type container aware? As an example I have 3 entities Account, User and Event. Users have ManyToMany relationship in order to associate many users with many other users (called approvers), reason for this is so that an Event created by a User can have a list of Users who area able approve it. In the User edit form where I have an approvers multiple select field the list needs to be filtered by Account so I need my form type to be container aware in order to

How to log all Doctrine queries to file?

旧街凉风 提交于 2019-12-12 10:43:20
问题 I'm using Doctrine and want to log all generated SQL queries. I know that I could use $q->getSqlQuery() but I don't want to do that manually each time. Is there a way to do it automatically? 回答1: If you turn logging on all queries shoudl be logged to your application log in the log directory. To do this set logging_enabled to true in your settings.yml . 回答2: Take a look at Doctrine Profiler and the source of ZF_Debug & Doctrine. 来源: https://stackoverflow.com/questions/2800226/how-to-log-all

Doctrine Query Class Not in Entity Directory

▼魔方 西西 提交于 2019-12-12 10:12:28
问题 My Entity directory for my bundle is getting quite large. I'd like to be able to group my classes into sub-directories. For example, all forum related classes in Entity/Forum/. I've been able to do this relatively successfully, but I don't know how to do a doctrine query now. The following doesn't work. SELECT fp FROM AcmeMainBundle:ForumPost fp WHERE 1 How do I query an entity not directly in the Entity Folder? 回答1: SELECT fp FROM AcmeMainBundle:Forum\ForumPost fp WHERE 1 This will work as

PHP-Doctrine2: Items - Shops - ItemsAtShops - how to conveniently implement using Doctrine2?

我与影子孤独终老i 提交于 2019-12-12 10:12:12
问题 Somehow I can't figure out how to implement the following relations using Doctrine 2 syntax: I have Items and Shops. Each item has different price and different quantity at each shop. So, I have Items table, Shops table and ItemsAtShops table. How do I reflect the last one in Doctrine? I guess I need to create ItemsAtShops entity, relates ManyToOne -> Items and ManyToOne -> Shops, right? But in this case... how do I conveniently fetch a list of Items at the specific Shops with their prices

composer install fails when unable to see mysql database

两盒软妹~` 提交于 2019-12-12 09:38:30
问题 TL;DR: composer install fails when the post-install scripts can't see a MySQL server I'm building a docker container for a Symfony application, and during the build I do something like this RUN export SYMFONY_ENV=prod && \ composer install --prefer-dist --optimize-autoloader Towards the end of the install, it fails with this Generating optimized autoload files [Doctrine\DBAL\Exception\DriverException] An exception occured in driver: SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127