все нормально идет
results = db_session.query(Game, Competition, Stage).filter(
((Game.home_name == 'Барселона') | (Game.guest_name == 'Барселона'))
).join(Competition).join(Stage).order_by(Game.date.desc())
for stats_game, competition, stage in results:
print(f'stats_game, competition, stage: {stats_game} {competition} {stage}')
stats_game, competition, stage: <models.Game object at 0x7f363679a5d0> <models.Competition object at 0x7f3636a70150> <models.Stage object at 0x7f363756fc90>
то есть Country убираем и все нормально идет results = db_session.query(Game, Competition, Stage).filter( ((Game.home_name == 'Барселона') | (Game.guest_name == 'Барселона')) ).join(Competition).join(Stage).order_by(Game.date.desc()) for stats_game, competition, stage in results: print(f'stats_game, competition, stage: {stats_game} {competition} {stage}') stats_game, competition, stage: <models.Game object at 0x7f363679a5d0> <models.Competition object at 0x7f3636a70150> <models.Stage object at 0x7f363756fc90>
results = db_session.query(Game, Competition, Stage, Country).join(Competition).join(Country).join(Stage).order_by(Game.date.desc()) for stats_game, competition, stage in results: print(f'stats_game, competition, stage: {stats_game} {competition} {stage}') пусто. то есть что-то не хочет работать join для Country. вопрос почему? может в models.py накосячил?
я же отправил запрос на пастбине 2023-05-20 01:48:43,934 INFO sqlalchemy.engine.Engine SELECT games.id AS games_id, games.game_id AS games_game_id, games.date AS games_date, games.competition_id AS games_competition_id, games.stage_id AS games_stage_id, games.home_name AS games_home_name, games.guest_name AS games_guest_name, games.home_score AS games_home_score, games.guest_score AS games_guest_score, games.competition AS games_competition, games.country_id AS games_country_id, competitions.id AS competitions_id, competitions.name AS competitions_name, competitions.show AS competitions_show, stages.id AS stages_id, stages.name AS stages_name, countries.id AS countries_id, countries.name AS countries_name FROM games JOIN competitions ON competitions.id = games.competition_id JOIN stages ON stages.id = games.stage_id JOIN countries ON countries.id = games.country_id 2023-05-20 01:48:43,935 INFO sqlalchemy.engine.Engine [cached since 143.2s ago] ()
Сорян, не видел выше сообщение
Так может просто нет таких данных, чтобы сразу в 4 таблицах все было?
данные точно есть сразу в 4 таблицах
Покажи пример
На всякий случай: ты знаешь разницу inner и outer join?
main1.py - без Country main2.py c Country #main1.py from models import Game, Stage, Competition, Country, db_session results = db_session.query(Game, Competition, Stage).join(Competition).join(Stage) for stats_game, competition, stage in results: print(f'stats_game, competition, stage: {stats_game} {competition} {stage}') stats_game, competition, stage: <models.Game object at 0x7f70ed237250> <models.Competition object at 0x7f70ee907d90> <models.Stage object at 0x7f70ed376510> stats_game, competition, stage: <models.Game object at 0x7f70ed2373d0> <models.Competition object at 0x7f70ee50ff90> <models.Stage object at 0x7f70eeb9b810> stats_game, competition, stage: <models.Game object at 0x7f70eca1a410> <models.Competition object at 0x7f70ee50ff90> <models.Stage object at 0x7f70eeb9b810> #main2.py from models import Game, Stage, Competition, Country, db_session results = db_session.query(Game, Competition, Stage, Country) for stats_game, competition, stage in results: print(f'stats_game, competition, stage, country: {stats_game} {competition} {stage} {country}') 2023-05-20 20:28:22,823 INFO sqlalchemy.engine.Engine SELECT games.id AS games_id, games.game_id AS games_game_id, games.date AS games_date, games.competition_id AS games_competition_id, games.stage_id AS games_stage_id, games.home_name AS games_home_name, games.guest_name AS games_guest_name, games.home_score AS games_home_score, games.guest_score AS games_guest_score, games.competition AS games_competition, games.country_id AS games_country_id, competitions.id AS competitions_id, competitions.name AS competitions_name, competitions.show AS competitions_show, stages.id AS stages_id, stages.name AS stages_name, countries.id AS countries_id, countries.name AS countries_name FROM games, competitions, stages, countries 2023-05-20 20:28:22,823 INFO sqlalchemy.engine.Engine [generated in 0.00048s] () ```
Три вижу, а четвертая? Страна вообще указана?
Вот в первом запросе ты вывел какие-то Game. Что там указано в качестве страны?
Обсуждают сегодня