Many to Many relationships | SQLAlchemy

Поделиться
HTML-код
  • Опубликовано: 12 янв 2022
  • In this video, I talk about many to many relationships in SQLAlchemy.
    When numerous records in one table are linked to several records in another table, this is known as a many-to-many relationship.
    Customers and products, for example, have a many-to-many relationship: customers can buy a variety of things, and products can be bought by a large number of customers.
    In this video, I use that example to explain how many to many relationships are created in SQLAlchemy. I also demonstrate how to configure delete behavior with many to many relationships.
    SUBSCRIBE:
    ruclips.net/user/SsaliJonathan...
    Please donate to this channel:
    www.buymeacoffee.com/jod35
    GITHUB:
    github.com/jod35
    TWITTER:
    / jod35_
  • НаукаНаука

Комментарии • 36

  • @choi-wav
    @choi-wav 2 года назад +1

    thank you so much for these tutorials, they have been extremely helpful. I've been trying to understand ORM with SQLAlchemy for a couple of months now and this series is the only one I've found that explores it in a way that makes sense to me, looking forward to your other videos!

  • @fvasquezl
    @fvasquezl 2 месяца назад

    Great Job, I'm to create my first fastapi exercises, and your videos have helped me a lot

    • @SsaliJonathan
      @SsaliJonathan  2 месяца назад

      Really glad my videos helped. Thanks for watching

  • @MaguinesBR
    @MaguinesBR Год назад

    perfect man, exactly that I was looking for

  • @mittamoa
    @mittamoa 2 года назад

    Thanks for the thorough explanation!

  • @tes6467
    @tes6467 2 года назад

    You made my day bro.. keep up the great work,, from Pakistan with Love!! ♥

  • @TheAremoh
    @TheAremoh 2 года назад

    Good tutorial as always. Well done

    • @SsaliJonathan
      @SsaliJonathan  2 года назад

      Thanks man, I really appreciate your support.

  • @SsaliJonathan
    @SsaliJonathan  2 года назад

    Thanks for watching.

  • @vagnerantoniodasilva2091
    @vagnerantoniodasilva2091 2 года назад

    Greate video !! congratulations!!

  • @Juanoetdm
    @Juanoetdm Год назад

    Awesome. Thank you.

  • @aldrickdev
    @aldrickdev 2 года назад +1

    Great video, though I do have a question. Why did you use the "remove" method instead of the "delete" method that you were using in the previous videos? Is there any difference? I am referring to 30:30

    • @SsaliJonathan
      @SsaliJonathan  2 года назад

      According to the docs
      docs.sqlalchemy.org/en/14/orm/basic_relationships.html
      The way you can delete a child object from a parent is by using the remove method.
      myparent.children.remove(somechild)

  • @zaiongomes4290
    @zaiongomes4290 2 года назад

    Você é o cara!!!

  • @neilshah184
    @neilshah184 Год назад

    cheers mate!

  • @cmtajr1746
    @cmtajr1746 2 года назад

    I'd like to know more about many-to-many self-relationships, such as follow and follower.

    • @SsaliJonathan
      @SsaliJonathan  2 года назад

      The same concept works. Though you will have primary keys of users. A very good example is found here.
      blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-viii-followers

    • @SsaliJonathan
      @SsaliJonathan  2 года назад

      Though it is a Flask example, I hope it gives you insight

    • @cmtajr1746
      @cmtajr1746 2 года назад

      @@SsaliJonathan
      This was very helpful!!
      Looking forward to fastapi's video!
      I've subscribed to your channel.

  • @ayowandeoluwatosin9365
    @ayowandeoluwatosin9365 Год назад

    Thank you, what If the association table as another column instead of just two column. How do you then insert into the database?

    • @SsaliJonathan
      @SsaliJonathan  Год назад

      think we can use the association table class. read about it here. docs.sqlalchemy.org/en/14/orm/basic_relationships.html#association-object

  • @martapfahl940
    @martapfahl940 8 месяцев назад

    Awful mic but still you helped me a lot brother :D Thank you

    • @SsaliJonathan
      @SsaliJonathan  8 месяцев назад +1

      Dont worry man. I got better audio and gonna release one for SQlAlchemy 2.0, Stay tuned

    • @martapfahl940
      @martapfahl940 8 месяцев назад

      @@SsaliJonathan You're the best

  • @fvasquezl
    @fvasquezl 2 месяца назад

    what about if we want to create a document to each model, one to product other to customer an other to relationship, How can we avoid circular import?

    • @SsaliJonathan
      @SsaliJonathan  2 месяца назад +1

      So you can create your database models in a single file or create them in their own. The trick is to create your base class in a single file where they could all get it from.
      Does it answer your question?
      If not, kindly give me more details

  • @srvazkez
    @srvazkez 2 года назад

    Amazing tutorial bro but how make query's form this type of relationship?

    • @SsaliJonathan
      @SsaliJonathan  2 года назад +1

      You can get objects with
      parent.children
      This will query for the children in the relationship.