{"id":100,"date":"2019-05-05T15:18:32","date_gmt":"2019-05-05T13:18:32","guid":{"rendered":"http:\/\/yohanan.fr\/?p=100"},"modified":"2019-05-13T21:48:45","modified_gmt":"2019-05-13T19:48:45","slug":"relation-many-to-many","status":"publish","type":"post","link":"https:\/\/yohanan.fr\/?p=100","title":{"rendered":"RELATION MANY TO MANY \/ BIT OF MASK"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\" style=\"text-align:left\">Pr\u00e9requis: <\/h4>\n\n\n\n<p style=\"text-align:left\" class=\"has-text-color has-background has-very-dark-gray-color has-very-light-gray-background-color wp-block-paragraph\"><strong>Les requ\u00eates sql ,  les relations entre les tables dans une base de donn\u00e9e ,  un minimum de connaissance sur l&rsquo;\u00e9criture d&rsquo;un nombre en base 2 <\/strong><\/p>\n\n\n\n<p class=\"has-drop-cap wp-block-paragraph\">Salut \u00e0 tous, hello ou bonjour, dans l&rsquo;article de ce jour, le premier de mon site je me propose de vous parler d&rsquo;une autre mani\u00e8re de g\u00e9rer les relations many to many ou les ralations de cardinale (n,n) dans les bases de donn\u00e9es.  Pour cela prenons l&rsquo;exemple d&rsquo;un logiciel qui veut g\u00e9rer l&rsquo;appartenance  de personne \u00e0 divers association. Dans notre exemple une association  pourra avoir plusieurs personnes et une personne pourra \u00eatre inscrit  dans plusieurs association on est donc face \u00e0 une relation many to many  et le mcd  et le mld des tables seront alors  :  <\/p>\n\n\n\n<ul class=\"wp-block-gallery columns-2 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"562\" src=\"http:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/association_participant.png\" alt=\"\" data-id=\"101\" class=\"wp-image-101\" srcset=\"https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/association_participant.png 1000w, https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/association_participant-300x169.png 300w, https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/association_participant-768x432.png 768w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"852\" height=\"479\" src=\"http:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/mldassociation-1.png\" alt=\"\" data-id=\"104\" data-link=\"http:\/\/yohanan.fr\/?attachment_id=104\" class=\"wp-image-104\" srcset=\"https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/mldassociation-1.png 852w, https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/mldassociation-1-300x169.png 300w, https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/mldassociation-1-768x432.png 768w\" sizes=\"auto, (max-width: 852px) 100vw, 852px\" \/><\/figure><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">On remarque que pour la gestion classique de la relation many to many, une table de liaison est cr\u00e9e, contenant l&rsquo;id de l&rsquo;association et l&rsquo;id du participant. Cette mani\u00e8re de faire peut parfois \u00eatre couteuse, et \u00eatre facteur de m\u00e9lange de m\u00e9tier des tables. L&rsquo;autre m\u00e9thode peut parfois \u00eatre facteur d&rsquo;\u00e9conomie de travail pour votre base de donn\u00e9e. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">BIT OF MASK <\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Supposons qu\u2019on g\u00e8re 4 association, l\u2019association A , l\u2019association B, l\u2019association C et l\u2019association D nous voulons pouvoir g\u00e9rer le fait qu\u2019une personne soit ou non  dans l\u2019association A, B, C ou D <br> Nous pourrions alors g\u00e9rer cela par un tableau, avec des valeurs bool\u00e9ennes repr\u00e9sent\u00e9es par les nombres 1 et 0, 1 une personne appartient \u00e0 l\u2019association et 0 le b\u00e9n\u00e9vole n\u2019appartient pas \u00e0 l\u2019association. <br> Ce qui donnerait alors pour une personne particuli\u00e8re <br><\/p>\n\n\n\n<table class=\"wp-block-table\"><tbody><tr><td>Association A<\/td><td> Association B <\/td><td> Association C<\/td><td> Association D <\/td><\/tr><tr><td>1<\/td><td>0<\/td><td>0<\/td><td>1<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p class=\"wp-block-paragraph\">Dans cette exemple la personne appartient \u00e0 l\u2019association A et D mais n\u2019appartient pas \u00e0 B et C <br> La suite de nombre (1,0,0,1) peut \u00eatre vu comme la repr\u00e9sentation unique d\u2019un nombre en base 2 <br> En traduisant cette suite en base 10, cela donnerait :<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1*<em>2^3+0*<\/em>2^2+ 0 * 2^1+1* 2^0 <br>= 8 + 1 = 9 <br> Le fait qu\u2019une personne appartienne \u00e0 l\u2019association A et D mais n\u2019appartient pas \u00e0 B et C peut donc \u00eatre traduit par le nombre 9<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">de plus en base 10 appartenir \u00e0 l\u2019association A peut-\u00eatre repr\u00e9senter par le nombre 2^3 = 8 <br>    en base 10 appartenir \u00e0 l\u2019association B peut \u00eatre repr\u00e9senter par le nombre 2^2 = 4 <br>    en base 10 appartenir \u00e0 l\u2019association C peut \u00eatre repr\u00e9senter par le nombre 2^1 = 2 <br>   en base 10 appartenir \u00e0 l\u2019association D peut \u00eatre repr\u00e9senter par le nombre 2^0 = 1 <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Le langage PHP, ainsi que sql nous offre l\u2019opportunit\u00e9 de travailler avec des op\u00e9rateurs sur les bits, ainsi si nous continuons dans notre exemple : <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>le b\u00e9n\u00e9vole appartient-il \u00e0 l\u2019association A ?  9&amp;8 = 8 renvoie true <\/li><li>le b\u00e9n\u00e9vole appartient-il \u00e0 l\u2019association B ?  9&amp;4 = 4 renvoie false <\/li><li>le b\u00e9n\u00e9vole appartient-il \u00e0 l\u2019association C ?  9&amp;2 = 2 renvoie false <\/li><li>le b\u00e9n\u00e9vole appartient-il \u00e0 l\u2019association B ?  9&amp;1 = 1 renvoie true  <\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">  Un tableau d\u2019appartenance de b\u00e9n\u00e9vole aux association A, B, C, D donnerait alors :<\/p>\n\n\n\n<table class=\"wp-block-table is-style-stripes\"><tbody><tr><td>Nom<\/td><td>Appartenance <\/td><\/tr><tr><td>Dupond<\/td><td>9<\/td><\/tr><tr><td>Didier<\/td><td>6<\/td><\/tr><tr><td>Roland<\/td><td>14<\/td><\/tr><tr><td>Robert<\/td><td>1<\/td><\/tr><\/tbody><\/table>\n\n\n\n<ul class=\"wp-block-list\"><li>Ainsi Dupond appartient \u00e0 l\u2019association A et D  <\/li><li>Didier appartient \u00e0 l\u2019association B et C  <\/li><li>Roland appartient \u00e0 l\u2019association A, B, et C  <\/li><li>Et Robert appartient \u00e0 l\u2019association D<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Le principe du bit of mask \u00e9tant \u00e9tablie,  reste \u00e0 l&rsquo;int\u00e9grer \u00e0 notre petit projet. Le mld et le mcd du projet deviennent  alors : <\/p>\n\n\n\n<ul class=\"wp-block-gallery columns-2 is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\"><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"479\" src=\"http:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/association_mld_participant.png\" alt=\"\" data-id=\"142\" data-link=\"http:\/\/yohanan.fr\/?attachment_id=142\" class=\"wp-image-142\" srcset=\"https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/association_mld_participant.png 1000w, https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/association_mld_participant-300x144.png 300w, https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/association_mld_participant-768x368.png 768w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"479\" src=\"http:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/association_mcd_participant.png\" alt=\"\" data-id=\"143\" data-link=\"http:\/\/yohanan.fr\/?attachment_id=143\" class=\"wp-image-143\" srcset=\"https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/association_mcd_participant.png 1000w, https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/association_mcd_participant-300x144.png 300w, https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/association_mcd_participant-768x368.png 768w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/figure><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Apr\u00e9s avoir int\u00e9gr\u00e9 des donn\u00e9es on \u00e0 alors sur phpmyadmin au niveau de la table associations: <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"546\" src=\"http:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/Capture_association-1024x546.png\" alt=\"\" class=\"wp-image-148\" srcset=\"https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/Capture_association-1024x546.png 1024w, https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/Capture_association-300x160.png 300w, https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/Capture_association-768x409.png 768w, https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/Capture_association.png 1366w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">au niveau de la table  participants on \u00e0 :<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"546\" src=\"http:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/Capture_participants-1024x546.png\" alt=\"\" class=\"wp-image-149\" srcset=\"https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/Capture_participants-1024x546.png 1024w, https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/Capture_participants-300x160.png 300w, https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/Capture_participants-768x409.png 768w, https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/Capture_participants.png 1366w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">si l&rsquo;on voudra recherch\u00e9 toute les association de Durand avec un id = 2 on fera la requ\u00eate suivante : \u00ab\u00a0<code><a href=\"http:\/\/localhost\/phpmyadmin\/url.php?url=https:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/select.html\">SELECT<\/a> * FROM `participants` INNER JOIN associations ON participants.filtrage_association_participant &amp; associations.cle_de_filtrage_association = associations.cle_de_filtrage_association WHERE participants.id = 2 \"<\/code> ce qui donnera le r\u00e9sultat suivant:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"291\" src=\"http:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/Capture_resultat_1-1024x291.png\" alt=\"\" class=\"wp-image-151\" srcset=\"https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/Capture_resultat_1-1024x291.png 1024w, https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/Capture_resultat_1-300x85.png 300w, https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/Capture_resultat_1-768x218.png 768w, https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/Capture_resultat_1.png 1113w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">si l&rsquo;on recherche toutes les personnes appartenant \u00e0 l&rsquo;association secours catholique avec pour id= 3 on fera la requ\u00eate suivante: <code><a href=\"http:\/\/localhost\/phpmyadmin\/url.php?url=https:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/select.html\">SELECT<\/a> * FROM `participants` INNER JOIN associations ON participants.filtrage_association_participant &amp; associations.cle_de_filtrage_association = associations.cle_de_filtrage_association WHERE associations.id = 3 <\/code> ce qui donnera pour r\u00e9sultat : <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"271\" src=\"http:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/Capture_resultat_2-1024x271.png\" alt=\"\" class=\"wp-image-152\" srcset=\"https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/Capture_resultat_2-1024x271.png 1024w, https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/Capture_resultat_2-300x79.png 300w, https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/Capture_resultat_2-768x203.png 768w, https:\/\/yohanan.fr\/wp-content\/uploads\/2019\/05\/Capture_resultat_2.png 1116w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Voila qui clos cette article, j\u2019esp\u00e8re avoir \u00e9t\u00e9 le plus complet possible \ud83d\ude09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pr\u00e9requis: Les requ\u00eates sql , les relations entre les tables dans une base de donn\u00e9e , un minimum de connaissance sur l&rsquo;\u00e9criture d&rsquo;un nombre en base 2 Salut \u00e0 tous, &#8230;<\/p>\n","protected":false},"author":1,"featured_media":156,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-100","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/yohanan.fr\/index.php?rest_route=\/wp\/v2\/posts\/100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yohanan.fr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yohanan.fr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yohanan.fr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yohanan.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=100"}],"version-history":[{"count":16,"href":"https:\/\/yohanan.fr\/index.php?rest_route=\/wp\/v2\/posts\/100\/revisions"}],"predecessor-version":[{"id":171,"href":"https:\/\/yohanan.fr\/index.php?rest_route=\/wp\/v2\/posts\/100\/revisions\/171"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/yohanan.fr\/index.php?rest_route=\/wp\/v2\/media\/156"}],"wp:attachment":[{"href":"https:\/\/yohanan.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yohanan.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yohanan.fr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}