Skip to content

Instantly share code, notes, and snippets.

@RichardLitt
Last active August 29, 2015 14:08
Show Gist options
  • Save RichardLitt/945ed7c461d834fff023 to your computer and use it in GitHub Desktop.
Save RichardLitt/945ed7c461d834fff023 to your computer and use it in GitHub Desktop.
## Places Model
Class Places
# I added through Houses, removed depdendent: :destroy (see comment)
has_many :campsites, dependent: :destroy
#has_many :days, dependent: :destroy
has_many :days, through: :houses
end
### Houses model
Class Houses
has_many :days, dependent: :destroy
belongs_to :places
end
### Controller
Class Dashboard::DaysController < ApplicationController
def home
places_id = params[:places_id]
@places = Places.includes(houses: [:days]).find(places_id)
# And now this is broken
@date_range = @places.days.group('id, date').count.keys.sort
end
@RichardLitt
Copy link
Author

PG::AmbiguousColumn: ERROR: column reference "id" is ambiguous LINE 1: SELECT COUNT() AS count_all, id, date AS id_date FROM "days... ^ : SELECT COUNT() AS count_all, id, date AS id_date FROM "days" INNER JOIN "houses" ON "days"."house_id" = "houses"."id" WHERE "houses"."place_id" = $1 GROUP BY id, date

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment