In an attempt to define a one-to-many relationship across bundles the following occurs:
The class 'Mana\ClientBundle\Entity\Member' was not found in the chain configured namespaces Mana\SplitBundle\Entity
I've now seen conflicting answers that the relationship can and cannot be accomplished. On the assumption that it can (because others here at stackoverflow seem to have done it), what configuration is required other than registering the bundles in AppKernel.php and entering the annotations in the entities? The resolve_target_entity_listener
did not appear to make a difference.
Well, I know I'm way out of my depth here, but this is what I observed while stepping through the code when trying to show a Client entity.
The error message in the profiler
The target entity 'Mana\ClientBundle\Entity\Member' specified on Mana\SplitBundle\Entity\Client#members is unknown or not an entity.
occurs because SchemaValidator evaluates $cmf->isTransient($assoc['targetEntity'])
to true, where the targetEntity in the Member entity. The PHPdoc comment suggests that this entity's metadata is not loaded. If I understand this correctly, that means that the annotation regarding the relationship is not loaded. But observing variable values suggests that the annotations have been read.
Am I totally missing something that should be painfully obvious? Or am I too far out in left field?
I have confirmed that doctrine:mapping:info
will detect improper FQCN. The data fixtures are correct. Use of entity managers and database-connection for both default and split connections are correct. The error persists and can occur for any of the relationships defined in the Client entity, either OneToMany or ManyToOne.
doctrine:
dbal:
default_connection: default
connections:
default:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
mapping_types:
enum: string
split:
driver: "%database_driver2%"
host: "%database_host2%"
port: "%database_port2%"
dbname: "%database_name2%"
user: "%database_user2%"
password: "%database_password2%"
charset: UTF8
mapping_types:
enum: string
entity_managers:
default:
connection: default
mappings:
ManaClientBundle: ~
split:
connection: split
mappings:
ManaSplitBundle: ~
/**
* @ORM\OneToMany(targetEntity="Mana\ClientBundle\Entity\Member", mappedBy="client")
* @ORM\OrderBy({"dob" = "ASC"})
*/
protected $members;
/**
* @ORM\ManyToOne(targetEntity="Mana\SplitBundle\Entity\Client",inversedBy="members",cascade={"remove", "persist"})
* @ORM\JoinColumn(name="cid", referencedColumnName="id")
*
*/
protected $client;
$ php app/console doctrine:mapping:info
Found 12 mapped entities:
[OK] Mana\ClientBundle\Entity\Agency
[OK] Mana\ClientBundle\Entity\Center
[OK] Mana\ClientBundle\Entity\Contact
[OK] Mana\ClientBundle\Entity\Contactdesc
[OK] Mana\ClientBundle\Entity\Counties
[OK] Mana\ClientBundle\Entity\Ethnicity
[OK] Mana\ClientBundle\Entity\Incomehistory
[OK] Mana\ClientBundle\Entity\Incomesrc
[OK] Mana\ClientBundle\Entity\Member
[OK] Mana\ClientBundle\Entity\Note
[OK] Mana\ClientBundle\Entity\Referral
[OK] Mana\ClientBundle\Entity\User
$ php app/console doctrine:mapping:info --em=split
Found 1 mapped entities:
[OK] Mana\SplitBundle\Entity\Client
You should see Using Relationships with Multiple Entity Managers
A cross-bundle relationship cannot be managed by Doctrine if you have separate databases with separate connections and entity managers. Instead, in this case, the Client entity would have to reside in the same schema/bundle and be periodically refreshed from the external source.
But if you have only one connection to the database and one entity manager for it you can manage cross-bundle relationships. (Described here: OneToMany Relation on cross project entities (Symfony2/Doctrine))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With