Insertion and removal using PDO in Onetomany and Manytomany relationships

Asked

Viewed 47 times

0

I beginner questions about inserting and removing using PDO in such relationships Onetomany and Manytomany. Example:

class Livro{
   private $id;
   private $titulo;
   private $generos; //Livro tem mais de um genero
}

class Genero{
   private $id;
   private $nome;
}

The relationship is Onetomany, IE, a book has many genres. If in BD I have a Jointable (livro_genero) how do I do the insert using PDO? And if the relationship is Manytomany?

class Funcionario{
   private $id;
   private $nome;
   private $projetos; //Um funcionario pode participar de vários projetos
}

class Projeto{
   private $id;
   private $titulo;
   private $funcionarios; //Um projeto tem vários funcionarios
}

On the bench I have the tables funcionario, projeto and funcionario_has_projeto.

PS: I cannot use Doctrine, so I would like examples of how to do this without using a ORM and using Mysql.

  • you want to simulate ORM behavior then?

  • Something like that.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.