Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.6.2 - Campo ManyToManyField #197

Open
engnogueira opened this issue Feb 2, 2020 · 0 comments
Open

3.6.2 - Campo ManyToManyField #197

engnogueira opened this issue Feb 2, 2020 · 0 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@engnogueira
Copy link
Owner

engnogueira commented Feb 2, 2020

Nessa aula vamos conhecer a maneira mais simples de se criar um relacionamento de muitas para muitos no Django: com auxílio do campo ManyToManyField.

Campo ManyToManyField

Documentação do Django sobre relacionamento de Muitos para Muitos

Query usada para listar tordas matrículas:

SELECT
turma.id,
turma.nome,
matricula.*,
base_user.id,
base_user.email

FROM
turmas_turma AS turma
INNER JOIN turmas_turma_matriculas AS matricula on turma.id = matricula.turma_id
INNER JOIN base_user on matricula.user_id = base_user.id
Query usada para filtrar alunos de uma turma:

SELECT
turma.id,
turma.nome,
matricula.*,
base_user.id,
base_user.email

FROM
turmas_turma AS turma
INNER JOIN turmas_turma_matriculas AS matricula on turma.id = matricula.turma_id
INNER JOIN base_user on matricula.user_id = base_user.id
WHERE turma.id= 2
Query usada para filtrar turmas de um aluno:

SELECT
turma.id,
turma.nome,
matricula.*,
base_user.id,
base_user.email

FROM
turmas_turma AS turma
INNER JOIN turmas_turma_matriculas AS matricula on turma.id = matricula.turma_id
INNER JOIN base_user on matricula.user_id = base_user.id
WHERE base_user.id = 1

@engnogueira engnogueira added the documentation Improvements or additions to documentation label Feb 2, 2020
@engnogueira engnogueira self-assigned this Feb 2, 2020
@engnogueira engnogueira reopened this Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant