2
我在我的應用程序中有幾個捆綁包,我想在表之間建立關係。 一個是我的User(StoreOwner),它位於UserBundle中,第二個是StoreBundle中的Store。如何避免與來自不同捆綁的實體的依賴關係
它們之間的關係是OneToMany(用戶 - >是 - > Store的所有者)。
商店
/**
* Description of Store
*
* @ORM\Table(name="Store")
* @ORM\Entity(repositoryClass="Traffic\StoreBundle\Repository\StoreRepository")
* @author bart
*/
class Store extends StoreModel {
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string $name
*
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank(
* message="Please provide your shop name"
*)
*/
protected $name;
/**
* @ORM\ManyToOne(targetEntity="Application\Sonata\UserBundle\Entity\StoreOwner", inversedBy="stores")
*
*/
protected $owner;
}
店主
/**
* @ORM\Entity
*
*/
class StoreOwner extends User implements StoreOwnerInterface {
/**
* @var type ArrayCollection()
*
* @ORM\OneToMany(targetEntity="Traffic\StoreBundle\Entity\Store", mappedBy="owner", cascade={"persist"})
*/
protected $stores;
}
我的問題是:
是否有任何解決方案,以避免StoreBundle和UserBundle之間的依賴關係,並保持ENTI之間的關係在學說中聯繫?
那是非常有用的,非常感謝您 – bratek
@bratek不要忘記將其標記爲回答。 – acme
Hi @ jakub-zalas, 我有一個類似的問題,但有更多的限制。也許你可以幫助我乾淨地解決這個問題。 我有一個關係的一個關係在一個實體內的一個Bundle,我不能/不應該修改。但我必須添加一個新的Bundle與反面實體。 Part <-n---1->整體。部分是不知道整個存在。我可以給Whole添加任何東西。 WholeBundle依賴於PartBundle。 – juanmf