I want to grab all downloads for a given product_id and list them by
download type. Download types is a sortable list (using a position
column in the table, and I want to make sure the download types are
sorted by that column). I’m thinking of something like this:
I’m trying to figure out what to put in the middle, some sort
of :joins clause, but I’m not sure how it should look. In my view, it
seems the most logical to me to start looping through download types,
then loop through downloads for the given download type.
SQLite3::SQLException: ambiguous column name: downloads.id: SELECT
“download_types”.“id” AS t0_r0, “download_types”.“name” AS t0_r1,
“download_types”.“position” AS t0_r2, “download_types”.“created_at” AS
t0_r3, “download_types”.“updated_at” AS t0_r4, “downloads”.“id” AS
t1_r0, “downloads”.“title” AS t1_r1, “downloads”.“part_number” AS
t1_r2, “downloads”.“download_type_id” AS t1_r3,
“downloads”.“created_at” AS t1_r4, “downloads”.“updated_at” AS t1_r5,
“downloads”.“download_file_name” AS t1_r6,
“downloads”.“download_content_type” AS t1_r7,
“downloads”.“download_file_size” AS t1_r8,
“downloads”.“download_updated_at” AS t1_r9 FROM “download_types” LEFT
OUTER JOIN “downloads” ON downloads.download_type_id =
download_types.id INNER JOIN “downloads” ON downloads.download_type_id
= download_types.id INNER JOIN “downloads_products” ON
“downloads_products”.download_id = “downloads”.id INNER JOIN
“products” ON “products”.id = “downloads_products”.product_id WHERE
(product.id = 58) ORDER BY position, download.title