Ruby on Rails
Sunday, June 23, 2019
Schema
-- create_table "days", force: :cascade do |t|
t.integer "season_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.date "raceday"
t.index ["season_id"], name: "index_days_on_season_id"
end
create_table "seasons", force: :cascade do |t|
t.date "year"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
@seasonmax = Season.last.id gives me me 7 the last id in the Seasons Table
@days = Day.find_by_sql("SELECT DISTINCT days.id,raceday FROM days INNER JOIN seasons on seasons.id WHERE days.season_id = @season_id") gives me an an empty list
@days = Day.find_by_sql("SELECT DISTINCT days.id,raceday FROM days INNER JOIN seasons on seasons.id WHERE days.season_id = 7") gives me the list I want
[#<Day id: 39, raceday: "2018-10-21">, #<Day id: 40, raceday: "2018-11-16">, #<Day id: 41, raceday: "2018-12-01">, #<Day id: 42, raceday: "2019-01-12">, #<Day id: 43, raceday: "2019-02-16">, #<Day id: 44, raceday: "2019-03-02">, #<Day id: 45, raceday: "2019-03-31">, #<Day id: 46, raceday: "2019-04-20">]
Why is the @seasonmax variable not picked in the SQL Query
@days = Day.find_by_sql("SELECT DISTINCT days.id,raceday FROM days INNER JOIN seasons on seasons.id WHERE days.season_id = @season_id")
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/d83efdba-feb9-4da2-b56e-f30a8009d2a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment