2013-03-28 67 views
0

我有兩個Entities,Plan和PricingTier。該計劃映射到我的計劃表並具有名爲pricing_tier_id的列。這通過其id列映射到PricingTiers表。實體具有從Plan到PricingTier的manyToOne關聯,以及從PricingTier到Plan的OneToMany關聯。這些都是下面:選擇關聯關鍵字的所有記錄

計劃實體

etrak\OnlineOrderProcessingBundle\Entity\Plan: 
    type: entity 
    table: plans 
    id: 
    id: 
     type: integer 
     generator: { strategy: AUTO } 
    fields: 
    name: 
     type: string 
     length: 255 
     nullable: true 
    description: 
     type: text 
     nullable: true 
    termsConditions: 
     column: terms_conditions 
     type: text 
     nullable: true 
    active: 
     type: boolean 
     nullable: true 
    amount: 
     type: decimal 
     nullable: true 
     scale: 2 
     precision: 5 
    affinity: 
     type: boolean 
     nullable: true 
    deactivationFee: 
     column: deactivation_fee 
     type: decimal 
     scale: 2 
     precision: 5 
     nullable: true 
    gracePeriodDays: 
     column: grace_period_days 
     type: integer 
     nullable: true 
    recurringInMonths: 
     column: recurring_in_months 
     type: integer 
     nullable: true 
    activeStartDate: 
     column: active_start_date 
     type: date 
    activeEndDate: 
     column: active_end_date 
     type: date 
    lifecycleCallbacks: 
    prePersist: [ prePersist ] 
    manyToOne: 
    pricingTier: 
     targetEntity: PricingTier 
     inversedBy: plans 
     joinColumn: 
     name: pricing_tier_id 
     referencedColumnName: id 

PricingTier實體

etrak\OnlineOrderProcessingBundle\Entity\PricingTier: 
    type: entity 
    table: pricing_tiers 
    id: 
    id: 
     type: integer 
     generator: { strategy: AUTO } 
    fields: 
    name: 
     type: string 
     length: 50 
    description: 
     type: string 
     length: 100 
     nullable: true 
    minimumDevices: 
     column: minimum_devices 
     type: integer 
    isAffinity: 
     column: is_affinity 
     type: boolean 
    keyname: 
     type: string 
     length: 55 
    createdBy: 
     column: created_by 
     type: string 
     length: 20 
    createdOn: 
     column: created_on 
     type: datetime 
    updatedOn: 
     column: updated_on 
     type: datetime 
     nullable: true 
    lifecycleCallbacks: 
    prePersist: [ onPrePersist ] 
    preUpdate: [ onPreUpdate ] 
    oneToMany: 
    plans: 
     targetEntity: Plan 
     mappedBy: pricingTier 
    oneToOne: 
    product: 
     targetEntity: Product 
     joinColumn: 
     name: product_id 
     referencedColumnName: id 

什麼,我需要做的是一樣的東西:SELECT * FROM WHERE計劃= pricing_tier_id 2

如果可能,我想遠離SQL/DQL。教義確實有內置的方法來做到這一點?請注意,我在Symfony 2.1中使用Doctrine作爲一個包。

回答

0

你能不只是找到你想要使用的存儲庫中的定價等級..

$pricingTier = $this->getDoctrine() 
        ->getRepository('OnlineOrderProcessingBundle:PricingTier') 
        ->find($id); 

然後你就可以訪問使用所有相關的計劃..

$pricingTier->getPlans() 

或在樹枝

{{ pricingTier.plans }} 
+0

這工作得很好!謝謝!一旦我打開PricingTier.php實體文件,我看到裏面有一個getPlans()方法:) – Ronny