Это видео недоступно.
Сожалеем об этом.

Creating Many-To-Many Relationships in Flask-SQLAlchemy

Поделиться
HTML-код
  • Опубликовано: 4 янв 2022
  • I talk about how to use Flask-SQLAlchemy to create many-to-many relationships between tables.
    Need one-on-one help with your project? I can help through my coaching program. Learn more here: prettyprinted....
    Join my free course on the basics of Flask-SQLAlchemy: prettyprinted....
    Get the code here: prettyprinted....
    Twitter: / pretty_printed
    Github: github.com/pre...

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

  • @nickapeed
    @nickapeed Год назад +14

    Small token for all the help you've provided over the years. Thank you again!

  • @miguelfernandes657
    @miguelfernandes657 2 года назад +17

    Probably the best explanation on Many-to-many relationships! Thanks!

  • @derickpambah
    @derickpambah 2 года назад +3

    Couldn't have said it any better. Thank you Anthony

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

    Anthony did not hesistate to make this video, all was fluently... Thanks!

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

    man, that was pricise.
    Thanks buddy

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

    Thank you for your videos, it helped me create relation for student and enrolled courses, so now the challenge is to add third entity which is time table allocated for each course and figure out conflict if any !!, wish me luck

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

    THANK YOU! I have spent hours and hours trying to figure this out! I wish I would have found your video sooner! I was close by help of stack overflow but still not quite there. Such good explanation as well! I thank you again. Keep up the great content!

  • @Skrcer
    @Skrcer 2 года назад +4

    Your vids are great, thanks a lot for all of them! Any chance you can upload a video about a Many-to-Many table with additional fields? I think it is called an association object.
    Thanks!

  • @ianpropst-campbell6028
    @ianpropst-campbell6028 Год назад

    Thank you for this helpful explanation of many to many relationships.

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

    Wow! I like your way to explained, is very easy to understand, thank you so much!!

  • @niello5944
    @niello5944 Год назад +1

    0:58 I wish the part about having other attributes in the relationship table is featured here because that's what I'm confused with and I can't find any where that explains it. This video mentioned how it's for another time but that doesn't seem to happen yet.

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

      Have you found an example for a third attribute?
      I want to add a permissions column to the association table where True would grant users certain rights. I've been able to add another column to association table but not yet edit it.

  • @ongayijohnian8787
    @ongayijohnian8787 4 месяца назад

    You shouldn't explain this well mahn😆, perfect stuff
    I watched the one to many, which you explained super well. I have quit this video less than halfway coz I already understand it following the one to many video. Thanks a lot mahn.

  • @lintingwei
    @lintingwei 2 года назад +2

    This is GOLD! Thank you 😀

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

    thanks for the service man, appreciate it

  • @vhaangol4785
    @vhaangol4785 2 года назад +2

    Please, make a tutorial for foreign key constraints in flask-sqlalchemy. There's really little info about it

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

    Hello... will be pleased if you can do an indepth tutorial on pydantic and fastapi with sql alchemy based on relationships... I know it sounds alot... thanks cheers

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

    How can i check if an inputted item is in say “erin.following”? I tried just doing “if input in erin.following:” and I defined Erin.following as something else but I don’t think this condition is ever being reached. As my flask app returns “view function has no return item” when this condition is suppose to be hitting. Advice?

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

    I get it!! I finally get it ! This was the best explanation for sure

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

    Amazingly Explained!

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

    You're a savior, thanks!

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

    Nice and Clean explanation 🤩

  • @GeorgeGasaway
    @GeorgeGasaway 3 месяца назад

    Is there an easy way to directly add rows to the association table without doing the append? Basically an INSERT to the association table with the id values. I have a large amount of data that I need to create association records for and it seems like it would be more efficient to directly add to those vs. querying the database to get objects for both sides of the association table and then linking them. Thank you for all that you do with your videos, super helpful!

    • @reubendinny9520
      @reubendinny9520 Месяц назад

      oh my lord! I was looking for the exact same thing. I was hoping we could just pass it as a parameter but nope

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

    Same code doesn't work for me...
    When I try to reproduce the terminal commands
    It says the app context isn't defined:
    This typically means that you attempted to use functionality that needed
    the current application. To solve this, set up an application context
    with app.app_context(). See the documentation for more information.

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

    Excellent video!

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

    Very good man!

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

    Thank you very much

  • @sujaljaine
    @sujaljaine 2 года назад +2

    Hey Anthony, another great video! ^_^ if you don't mind me asking this but I was just checking to see if ya got any other channels but it seems you had subscriptions public so didcha subscribe all the channels by hand or used a bot or something :p . I am really curious almost if not all the programming channels are subscribed I've ever heard of XO.

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

      I've subscribed to all of the channels myself. I'll subscribe to pretty much any channel I come across that makes programming content.

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

      @@prettyprinted hi there, now I am officially a university student and really would have liked to explore other programming channels for different topics unfortunately you don't cover. ANYWAYS, did you remove subscriptions to all of them? It could have come in handy.

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

    life-saver, thank you

  • @dafnegarcia7321
    @dafnegarcia7321 Год назад +1

    Hi, what happen if the relationship table has another attribute (ex: is_required), how can I add the element in the table using a similar notation ex: erin.following( mrbeast, True)?. Thanks

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

    bro it's fire, thanks a lot!

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

    I wanted to see how u did this in flask instead of the console cause flask just says that query object has not attr 'table name'

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

    Thank you so much

  • @xdprogrammer9579
    @xdprogrammer9579 10 месяцев назад

    Thanx for the video I am suffering from this error "sqlalchemy.exc.ArgumentError: Mapper Mapper[User(user)] could not assemble any primary key columns for mapped table 'user'" help plss;

  • @donmikele07
    @donmikele07 5 месяцев назад

    Is there a way to toggle in join table between users and channels? I mean if you click on some button on UI, and if there is a join between 2 entities to delete that row in the join table, otherwise to create a new record in join table? Thanks

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

    Hi Anthony can please make a video on how to store latitude and longitude in django models, in addition to that how to query and get the top nearest entires based on some input. I found something called geodjango put its hard to understand and it have like geometry and spatial indexes. I'm a little confused which one to choose.

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

    How do you query the table created using db.table

  • @user-gf3hf5ri8b
    @user-gf3hf5ri8b 2 года назад

    nice video! But does anyone know how to access the association table?
    if we add fields to association table, then how to access those fields having in mind that association table has no model.

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

    Hi is there a way to query the joins table to get all the entries inside of the joins table??

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

    Bro you are amazing

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

    how to add these terminal command to program, i am getting an error "object attached to a session"

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

    Legendary!

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

    Hey how can i use 1 sqlite db with 2 different flask web app

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

    You're the best

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

    Thanks for the tutorial. I have a small problem that you might help me with: I've created the users and channels as you did (e.g. anthony=User(name='Anthony') and closed VScode. When I reopened it, I imported everything (from main import db,User,Channel), but for some reason when I try to do something with the users, such as "anthony.followers.append(prettyprinted)", it returns "NameError: name 'anthony' is not defined". For some reason, variables that I created before (and exist in my database) are not received by the app if I close VScode and open it back. Can anyone help me with this problem?

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

      When close and reopen you need to define the variables again, just execute anthony=User(name='Anthony'). Also, don't forget to commit your changes.

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

      Thank you guys!

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

    How can we inherit the relationships that are already defined in a db?

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

      SQLAlchemy has the ability to autocreate models from existing database tables. Here's a video where I talk about it: ruclips.net/video/UK57IHzSh8I/видео.html

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

      @@prettyprinted you're the greatest. It's time for you to publish a book on O'Reilly or packt.

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

      @@chriskeo392 Maybe one day

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

    Hey Anthony!
    Can you please explain how to make this same job for 3 tables? like
    table: MATCH_USER_RESOURCE
    id | match_id | user_id | resource_id
    apparently it only works with 2 pks
    Thank you!

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

      Short answer: You don't
      What exactly do you want to achieve or to paraphrase it: What should this relationship represent?

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

      @@historynerd6630 What if you wanna make a User table, Group table and Role table, Where there is a many to many relationship between them because a user can be a part of different groups and have a different role in each group

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

      @@awesomedude7262 Given there are two groups (G1 and G2) and 3 possible roles (guest, user and moderator). Having a certain role in one group does not say anything about having (or not) the same role in the other group. Therefore it's globally not the same ROLE. So you could say there are actually 6 roles: guest@G1, user@G1, moderator@G1, guest@G2, user@G2 and moderator@G2 right? This could be represented by a table (ROLE_AT) with 6 rows for those 6 combinations and 3 columns: ROLE_id (primary key), GROUP, ROLE. Last thing you need is an association table for your many to many relation between USER table and ROLE_AT table.

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

    nice video