Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/05/2016, 08:00
hamramr
 
Fecha de Ingreso: marzo-2007
Mensajes: 59
Antigüedad: 17 años, 1 mes
Puntos: 0
Doble duda (bases de datos y Symfony-Doctrine)

Buenas.
Tengo una doble duda que pertenece tanto al apartado de bases de datos como a Symfony-Doctrine.

Tengo una tabla de vehiculos definida así:
Código:
CREATE TABLE `vehiculos` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `id_usuario` bigint(20) NOT NULL,
  `id_vehiculos_tipo` bigint(20) NOT NULL,
  `matricula` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  `seguro` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
  `fecha_proxima_itv` date NOT NULL,
  `vehiculo_principal` tinyint(1) NOT NULL,
  PRIMARY KEY (`id`)
)
Y otra de vehiculos_tipos así:
Código:
CREATE TABLE `vehiculos_tipos` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `descripcion_vehiculo` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`)
)
Las he definido mediante las entidades:
Vehiculos.php

Código PHP:
<?php

namespace AppBundleEntity
;

use 
DoctrineORMMapping as ORM;

/**
 * Vehiculos
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="AppBundle\Entity\VehiculosRepository")
 */
class Vehiculos
{
    
/**
     * @var integer
     *
     * @ORM\Column(name="id", type="bigint")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    
private $id;

    
/**
     * @var integer
     *
     * @ORM\Column(name="id_usuario", type="bigint")
     */
    
private $idUsuario;

    
/**
     * @var integer
     *
     * @ORM\Column(name="id_vehiculos_tipo", type="bigint")
     */
    
private $idVehiculosTipo;

    
/**
     * @var string
     *
     * @ORM\Column(name="matricula", type="string", length=50)
     */
    
private $matricula;

    
/**
     * @var string
     *
     * @ORM\Column(name="seguro", type="string", length=200)
     */
    
private $seguro;

    
/**
     * @var \DateTime
     *
     * @ORM\Column(name="fecha_proxima_itv", type="date")
     */
    
private $fechaProximaItv;

    
/**
     * @var boolean
     *
     * @ORM\Column(name="vehiculo_principal", type="boolean")
     */
    
private $vehiculoPrincipal;


    
/**
     * Get id
     *
     * @return integer 
     */
    
public function getId()
    {
        return 
$this->id;
    }

    
/**
     * Set idUsuario
     *
     * @param integer $idUsuario
     * @return Vehiculos
     */
    
public function setIdUsuario($idUsuario)
    {
        
$this->idUsuario $idUsuario;

        return 
$this;
    }

    
/**
     * Get idUsuario
     *
     * @return integer 
     */
    
public function getIdUsuario()
    {
        return 
$this->idUsuario;
    }

    
/**
     * Set idVehiculosTipo
     *
     * @param integer $idVehiculosTipo
     * @return Vehiculos
     */
    
public function setIdVehiculosTipo($idVehiculosTipo)
    {
        
$this->idVehiculosTipo $idVehiculosTipo;

        return 
$this;
    }

    
/**
     * Get idVehiculosTipo
     *
     * @return integer 
     */
    
public function getIdVehiculosTipo()
    {
        return 
$this->idVehiculosTipo;
    }

    
/**
     * Set matricula
     *
     * @param string $matricula
     * @return Vehiculos
     */
    
public function setMatricula($matricula)
    {
        
$this->matricula $matricula;

        return 
$this;
    }

    
/**
     * Get matricula
     *
     * @return string 
     */
    
public function getMatricula()
    {
        return 
$this->matricula;
    }

    
/**
     * Set seguro
     *
     * @param string $seguro
     * @return Vehiculos
     */
    
public function setSeguro($seguro)
    {
        
$this->seguro $seguro;

        return 
$this;
    }

    
/**
     * Get seguro
     *
     * @return string 
     */
    
public function getSeguro()
    {
        return 
$this->seguro;
    }

    
/**
     * Set fechaProximaItv
     *
     * @param \DateTime $fechaProximaItv
     * @return Vehiculos
     */
    
public function setFechaProximaItv($fechaProximaItv)
    {
        
$this->fechaProximaItv $fechaProximaItv;

        return 
$this;
    }

    
/**
     * Get fechaProximaItv
     *
     * @return \DateTime 
     */
    
public function getFechaProximaItv()
    {
        return 
$this->fechaProximaItv;
    }

    
/**
     * Set vehiculoPrincipal
     *
     * @param boolean $vehiculoPrincipal
     * @return Vehiculos
     */
    
public function setVehiculoPrincipal($vehiculoPrincipal)
    {
        
$this->vehiculoPrincipal $vehiculoPrincipal;

        return 
$this;
    }

    
/**
     * Get vehiculoPrincipal
     *
     * @return boolean 
     */
    
public function getVehiculoPrincipal()
    {
        return 
$this->vehiculoPrincipal;
    }
}

Y VehiculosTipos.php:

Código PHP:
<?php

namespace AppBundleEntity
;

use 
DoctrineORMMapping as ORM;

/**
 * VehiculosTipos
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="IP\RestBundle\Entity\VehiculosTiposRepository")
 */
class VehiculosTipos
{
    
/**
     * @var integer
     *
     * @ORM\Column(name="id", type="bigint")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    
private $id;

    
/**
     * @var string
     *
     * @ORM\Column(name="descripcion_vehiculo", type="string", length=100)
     */
    
private $descripcionVehiculo;


    
/**
     * Get id
     *
     * @return integer 
     */
    
public function getId()
    {
        return 
$this->id;
    }

    
/**
     * Set descripcionVehiculo
     *
     * @param string $descripcionVehiculo
     * @return VehiculosTipos
     */
    
public function setDescripcionVehiculo($descripcionVehiculo)
    {
        
$this->descripcionVehiculo $descripcionVehiculo;

        return 
$this;
    }

    
/**
     * Get descripcionVehiculo
     *
     * @return string 
     */
    
public function getDescripcionVehiculo()
    {
        return 
$this->descripcionVehiculo;
    }
}
Pues bien, la idea es que la tabla de vehículos contiene los vehículos de los usuarios de la base de datos y esta tabla tiene un campo "id_vehiculos_tipos" que se relaciona con el campo "id" de la tabla vehiculos_tipos. Es decir, por ejemplo, la tabla vehiculos_tipos puede tener:
id | descripcion_vehiculo
1 | Moto
2 | Coche
3 | Furgoneta

Y en la tabla vehiculos un usuario puede tener 2 vehículos, por ejemplo:
id | id_usuario | id_vehiculos_tipo | matricula | seguro | fecha_proxima_itv | vehiculo_principal
1 | 23 | 1 | 1234abc | ... | ... | 1
2 | 23 | 3 | 6789xyz | ... | ... | 0

Pues bien, dicho todo esto mi primera duda surge en algo que no tengo mucha experiencia.
1. Las relaciones entre estas tablas ¿de qué tipo son? Si no me equivoco sería de uno a muchos desde la tabla vehiculos_tipos a la tabla vehiculos ¿Correcto?

Y la segunda duda.
2. En tal caso, ¿cómo se define esto en Symfony?

Muchas gracias por la ayuda.
Un saludo.