在Symfony中编辑注册表时出错

时间:2017-08-02 17:28:25

标签: symfony dql

我有两个表var connString = from firstTable in _dataContext.Connections join secondTable in _dataContext.Companies on firstTable.CompanyID equals secondTable .CompanyID where secondTable .CompanyName == "Name" select firstTable .ConnectionString; Orders之间的关系,信息显示正确。

映射用户:

Users

映射订单:

BackendBundle\Entity\Users:
type: entity
table: users
id:
    id:
        type: integer
        nullable: false
        options:
            unsigned: false
        id: true
        column: ID
        generator:
            strategy: IDENTITY
fields:
    username:
        type: string
        nullable: true
        length: 50
        options:
            fixed: false
    yourname:
        type: string
        nullable: true
        length: 50
        options:
            fixed: false
    firstname:
        type: string
        nullable: true
        length: 150
        options:
            fixed: false
    lastname:
        type: string
        nullable: true
        length: 150
        options:
            fixed: false
    middlename:
        type: string
        nullable: true
        length: 10
        options:
            fixed: false
    address:
        type: string
        nullable: true
        length: 500
        options:
            fixed: false
    address2:
        type: string
        nullable: true
        length: 500
        options:
            fixed: false
    apartment:
        type: string
        nullable: true
        length: 50
        options:
            fixed: false
    pobox:
        type: string
        nullable: true
        length: 50
        options:
            fixed: false
    city:
        type: string
        nullable: true
        length: 150
        options:
            fixed: false
    state:
        type: string
        nullable: true
        length: 150
        options:
            fixed: false
    zipcode:
        type: string
        nullable: true
        length: 100
        options:
            fixed: false
    country:
        type: string
        nullable: true
        length: 255
        options:
            fixed: false
    countrycode:
        type: string
        nullable: true
        length: 2
        options:
            fixed: false
    phone:
        type: string
        nullable: true
        length: 150
        options:
            fixed: false
    fax:
        type: string
        nullable: true
        length: 150
        options:
            fixed: false
    email:
        type: string
        nullable: true
        length: 255
        options:
            fixed: false
    password:
        type: string
        nullable: true
        length: 50
        options:
            fixed: false
    company:
        type: string
        nullable: true
        length: 255
        options:
            fixed: false
    type:
        type: decimal
        nullable: true
        precision: 18
        scale: 0
    datein:
        type: datetime
        nullable: true
lifecycleCallbacks: {  }

我需要编辑订单记录,所以我将以下代码放在列表中:

BackendBundle\Entity\Orders:
type: entity
table: orders
indexes:
    fk_order_user1_idx:
        columns:
            - user_id
id:
    orderid:
        type: integer
        nullable: false
        options:
            unsigned: false
        id: true
        column: OrderID
        generator:
            strategy: IDENTITY
fields:
    orderdate:
        type: datetime
        nullable: true
        column: OrderDate
    ordernumber:
        type: string
        nullable: true
        length: 50
        options:
            fixed: false
        column: OrderNumber
    customername:
        type: string
        nullable: true
        length: 250
        options:
            fixed: false
        column: CustomerName
    customeraddress:
        type: string
        nullable: true
        length: 500
        options:
            fixed: false
        column: CustomerAddress
    countrycode:
        type: string
        nullable: true
        length: 2
        options:
            fixed: false
        column: CountryCode
    shippingaddress:
        type: string
        nullable: true
        length: 500
        options:
            fixed: false
        column: ShippingAddress
    status:
        type: string
        nullable: true
        length: 50
        options:
            fixed: false
        column: Status
    subtotal:
        type: decimal
        nullable: true
        precision: 18
        scale: 2
        column: SubTotal
    shippingcost:
        type: decimal
        nullable: true
        precision: 18
        scale: 2
        column: ShippingCost
    tax:
        type: decimal
        nullable: true
        precision: 18
        scale: 2
        column: Tax
    discount:
        type: decimal
        nullable: true
        precision: 18
        scale: 2
        column: Discount
    totalorder:
        type: decimal
        nullable: true
        precision: 18
        scale: 2
        column: TotalOrder
    shippingcarrier:
        type: string
        nullable: true
        length: 50
        options:
            fixed: false
        column: ShippingCarrier
    shippingtype:
        type: string
        nullable: true
        length: 50
        options:
            fixed: false
        column: ShippingType
    shippingtrackingnumber:
        type: string
        nullable: true
        length: 50
        options:
            fixed: false
        column: ShippingTrackingNumber
    paymentmethod:
        type: string
        nullable: true
        length: 50
        options:
            fixed: false
        column: PaymentMethod
    paymentapproval:
        type: string
        nullable: true
        length: 100
        options:
            fixed: false
        column: PaymentApproval
    cc:
        type: string
        nullable: true
        length: 20
        options:
            fixed: false
        column: CC
    ccexp:
        type: string
        nullable: true
        length: 10
        options:
            fixed: false
        column: CCExp
    ccv:
        type: string
        nullable: true
        length: 10
        options:
            fixed: false
        column: CCV
    memo:
        type: string
        nullable: true
        length: 500
        options:
            fixed: false
        column: Memo
    sessionid:
        type: string
        nullable: true
        length: 50
        options:
            fixed: false
        column: SessionID
    discountcode:
        type: string
        nullable: true
        length: 50
        options:
            fixed: false
        column: DiscountCode
    hasshipgift:
        type: boolean
        nullable: true
        column: HasShipGift
    message:
        type: string
        nullable: true
        length: 300
        options:
            fixed: false
    imagen:
        type: integer
        nullable: true
        options:
            unsigned: false
    siteType:
        type: string
        nullable: true
        length: 50
        options:
            fixed: false
        column: site_type
    shippingname:
        type: string
        nullable: true
        length: 250
        options:
            fixed: false
        column: ShippingName
manyToOne:
    user:
        targetEntity: Users
        cascade: {  }
        fetch: LAZY
        mappedBy: null
        inversedBy: null
        joinColumns:
            user_id:
                referencedColumnName: id
        orphanRemoval: false
lifecycleCallbacks: {  }

但是当它到达控制器的那一刻我有这个代码:

<td><a class="btn btn-primary" href="{{path('edit_orderlist',{ 'id': ordenes.orderid })}}">Edit</a></td>

它向我显示了这个错误:

  

无法解析类“BackendBundle \ Entity \ Users”的列“id”的类型

$em = $this->getDoctrine()->getManager(); $orders_repo=$em->getRepository("BackendBundle:Orders"); $order=$orders_repo->find($id); $form = $this->createForm(OrderType::class, $order); Orders个主键,用户为主键OrderId

有什么想法解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

在调查和阅读不同的建议之后,问题出现在表的.yml文件中,并且在实体中,Symfony显示此错误

introducir la descripción de la imagen aquí

要验证这一点,请创建测试环境并执行导入和创建实体以检查是否存在任何错误。

以下是代码:

//BackendBundle\Entity\Orders:
type: entity
table: orders
indexes:
    fk_Orders_Users_idx:
        columns:
            - Users_ID
......
manyToOne:
    users:
        targetEntity: Users
        cascade: {  }
        fetch: LAZY
        mappedBy: null
        inversedBy: null
        joinColumns:
            Users_ID:
                referencedColumnName: ID
        orphanRemoval: false
lifecycleCallbacks: {  }

Users.orm.yml与之前相同

另一项变更是在实体Orders.php

/**
 * @var \BackendBundle\Entity\Users
 */
private $users;
.........
/**
 * Set users
 *
 * @param \BackendBundle\Entity\Users $users
 *
 * @return Orders
 */
public function setUsers(\BackendBundle\Entity\Users $users = null)
{
    $this->users = $users;

    return $this;
}

/**
 * Get users
 *
 * @return \BackendBundle\Entity\Users
 */
public function getUsers()
{
    return $this->users;
}

通过这些改变一切正常。