Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveStorage Support? #582

Open
berniechiu opened this issue Oct 10, 2022 · 1 comment
Open

ActiveStorage Support? #582

berniechiu opened this issue Oct 10, 2022 · 1 comment

Comments

@berniechiu
Copy link

berniechiu commented Oct 10, 2022

Hi @cfis, thanks for the nice gem.

Currently we have a simple setup

class Rating < RivoApplicationRecord
  self.primary_keys = :id, :shop_id

  has_many_attached :images
  ...
end

Basically ActiveStorage polymorphic table only supports one primary id under record_id for storage, but that's fine. We would just want to continue to record the :id instead of [:id, :shop_id]

At the moment, the fetching looks fine

# Rails Console
rating = Rating.first
rating.images.first
# ActiveStorage::Attachment Load (1.5ms) 
# SELECT "active_storage_attachments".* FROM "active_storage_attachments"
# WHERE "active_storage_attachments"."record_id" = 1 AND "active_storage_attachments"."record_type" = 'Rating' 
# AND "active_storage_attachments"."name" = 'images' ORDER BY "active_storage_attachments"."id" ASC LIMIT 1

Screen Shot 2022-10-10 at 6 23 49 PM

However, the attach action can't seem to grep any :id correctly.

rating.images.attach(io: Down.download(url), filename: "test1")

#  ActiveStorage::Attachment Create (2.1ms)  INSERT INTO "active_storage_attachments" ("name", "record_type", "record_id", "blob_id", "created_at")
# VALUES ('images', 'Rating', NULL, 16, '2022-10-10 07:59:35.600141') RETURNING "id"

# ActiveRecord::NotNullViolation: PG::NotNullViolation: ERROR:  null value in column "record_id" violates not-null constraint

Thanks for you help!

@cfis
Copy link
Contributor

cfis commented Oct 15, 2022

Hmm, sorry, haven't ever used ActiveStorage. Happy to take a patch if you want to work out a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants