0

Tengo una relación entre 2 tablas Orders y Users y se muestra la información correctamente.

Mapping 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: {  }

Mapping Orders:

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: {  }

Necesito editar un registro de orders por lo que coloco en el listado el siguiente código:

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

Pero al momento que llega al controlador que tengo con este código:

$em = $this->getDoctrine()->getManager();
    $orders_repo=$em->getRepository("BackendBundle:Orders");
    $order=$orders_repo->find($id);
    $form = $this->createForm(OrderType::class, $order);

Me muestra este error:

Could not resolve type of column "id" of class "BackendBundle\Entity\Users"

Orders tiene como clave primaria OrderId y Users como clave primaria id

¿Alguna idea para solucionar esto?

2 respuestas 2

0

Hola juanitourquiza asegurate que en tus archivos doctrine xml tengas algo como esto:

AuthBundle\Resources\config\doctrine\Marcacion.orm.yml

Usuarios\AuthBundle\Entity\Marcacion:
type: entity
table: marcacion
id:
    id:
        type: integer
        nullable: false
        options:
            unsigned: false
        id: true
        generator:
            strategy: IDENTITY

y en el archivo: AuthBundle\Resources\config\doctrine\metadata\orm\Marcacion.orm.xml

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
  <entity name="Marcacion" table="marcacion">
    <id name="id" type="integer" column="id">
      <generator strategy="IDENTITY"/>
    </id>

en ambos archivos debe indicar que el id es IDENTITY.

1
  • Gracias tu respuesta. Agregue el mapeo en yml que tengo en las tablas Users y Orders. No utilizo el archivo .xml , voy a revisar lo que indicas. Commented el 2 ago. 2017 a las 19:21
0

Después de investigar y leer las diferentes recomendaciones, el problema estaba en los archivos .yml de las tablas y en las Entidades, además que encontré este error a pesar de que en pantalla el listado se veía bien.

introducir la descripción de la imagen aquí

Para verificar esto cree un ambiente de pruebas y realice la importación y creación de entidades para revisar si existía algún error.

Así quedo el código:

//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 quedo igual que antes

Otro cambio esta en la Entidad 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;
}

Con estos cambios todo funciona bien.

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.