Ver Mensaje Individual
  #2 (permalink)  
Antiguo 23/11/2014, 06:23
Avatar de Dundee
Dundee
 
Fecha de Ingreso: junio-2002
Ubicación: El Médano
Mensajes: 1.310
Antigüedad: 21 años, 10 meses
Puntos: 8
Respuesta: Claves primarias compuestas (composite primary key)

Bueno parece que he conseguido lo que quería pero a medias, como decía mi clave primaria la forman la Id y el BookId; pero al aplicar el método find de este modo:

Código PHP:
    // Parent branch. // $parent_branch_id is really the branch id.
   
$parent_branch $em->getRepository('BranchMainBundle:Branch')->find(array(
     
'id' => $parent_branch_id
     
'book_id' => $book_id
       
)); 
Obtengo este error que no entiendo.
Código PHP:
WarningMissing argument 1 for BranchMainBundleEntityBranch::__construct(), called in /var/www/html/piramidal/src/Branch/MainBundle/Controller/DefaultController.php on line 79 and defined in /var/www/html/piramidal/src/Branch/MainBundle/Entity/Branch.php line 34 
El método en cuestión __contruct() es simplemente esto: (no pego el resto de código setter y getters porque ya lo he puesto antes).

Código PHP:
  /**
   * @var integer
   *
   * @ORM\Column(name="id", type="integer", nullable=false)
   * @ORM\Id
   * @ORM\Column(type="integer")
   */
  
private $id;

  
/**
   * @var intenger
   * 
   * @ORM\Column(name="book_id", type="integer", nullable=false)
   * @ORM\Id
   * @ORM\ManyToOne(targetEntity="Book", inversedBy="Branch")
   */
  
private $book_id;

  public function 
__construct($id$book_id) {
    
$this->id $id// The branch id.
    
$this->book_id $book_id// The book id.
  

Estoy revisando esto, pero no consigo que me funcione, y creo que lo tengo igual.
Esta clarísimo que el problema esta al llamar al __contruct, ya que si le meto datos por defecto a los parámetro , si funciona:
Código PHP:
  public function __construct($id 1$book_id 1) {
    
$this->id $id// The branch id.
    
$this->book_id $book_id// The book id.
  

¿El método find no crea a su vez el objeto?. He probado creando el objeto sin usar find, pero obtengo el mismo error de __construct().
Código:
Warning: Missing argument 1 for Branch\MainBundle\Entity\Branch::__construct(), called in /var/www/html/piramidal/src/Branch/MainBundle/Controller/DefaultController.php on line 69 and defined in /var/www/html/piramidal/src/Branch/MainBundle/Entity/Branch.php line 33
Código PHP:
$parent_branch = new Branch(1,1); 
Bueno sigo probando cositas como esto:
Código PHP:
$parent_branch = new Branch(array( 'id' => 1'book_id' => 1)); 
Pero el resultado es el mismo error del __construct()
¿Alguna idea?.
Gracias de antemano.
__________________
Videotutoriales de Drupal

Última edición por Dundee; 23/11/2014 a las 06:44