0

我有两个实体,计划和定价层。计划映射到我的计划表并有一个名为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

定价层实体

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 plans WHERE pricing_tier_id = 2

如果可能的话,我想远离 SQL/DQL。Doctrine 肯定有内置的方法来做到这一点吗?请注意,我在 Symfony 2.1 中使用 Doctrine 作为捆绑包。

4

1 回答 1

0

您能否不只是使用存储库找到您想要的定价层..

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

然后您可以使用..访问所有相关计划

$pricingTier->getPlans()

或者在树枝上

{{ pricingTier.plans }}
于 2013-03-28T15:20:38.173 回答