Posts

Showing posts with the label one-to-many

SQL ont-to-may relationship - How to SELECT rows depending on multiple to-many properties?

SQL ont-to-may relationship - How to SELECT rows depending on multiple to-many properties? A MySQL database contains two tables with a one-to-many relationship: One user can have many settings: Users: id username password -------------------------- 1 Bob 123 2 Alice abc ... Settings: id user_id key value ----------------------------- 1 1 color blue // Bobs settings... 2 1 theme xy 3 1 size 5 4 2 size 6 // Alices settings... Problem: How to find all users with color == blue AND size == 5 ? color == blue AND size == 5 Using a LEFT JOIN it is no problem to find users with one property: LEFT JOIN SELECT users.id FROM users LEFT JOIN settings ON users.id = settings.user_id WHERE settings.key = 'color' AND settings.value = 'blue' However, this does not work when searching for two settings at a time? Is it possible to solve this with a single statement? What is the most efficient...

Symfony 4 : doctrine, relationships and twig

Image
Symfony 4 : doctrine, relationships and twig I'm currently working on my first symfony 4 project and I'm having a problem with my twig templating. First of all here is a UML diagram of my created objects. And my layout should look sorta like this : Here are my entities : Region <?php namespace AppEntity; use DoctrineCommonCollectionsArrayCollection; use DoctrineCommonCollectionsCollection; use DoctrineORMMapping as ORM; /** * @ORMEntity(repositoryClass="AppRepositoryRegionRepository") */ class Region { /** * @ORMId() * @ORMGeneratedValue() * @ORMColumn(type="integer") */ private $id; /** * @ORMColumn(type="string", length=255) */ private $designation; /** * @ORMOneToMany(targetEntity="AppEntityCountry", mappedBy="region", orphanRemoval=true) */ private $countries; /** * @ORMColumn(type="string", length=255) */ private $initials; ...