-
Notifications
You must be signed in to change notification settings - Fork 0
Description
First of all: thx for releasing this gem! π
I had a first look and saw these lines in the generated migration:
t.index :owner_id if foreign_key_type # Index owner_id only if it's a separate column
t.index :owner_type if foreign_key_type # Index owner_type only if it's a separate columnwhich kinda make it look like you planned to make it configurable? But the migration also contains:
# Who owns this key? Can be null for ownerless keys.
t.references :owner, polymorphic: true, null: true, type: foreign_key_typeand the ApiKey class:
belongs_to :owner, polymorphic: true, optional: trueIn my use case I would only allow my Organization model to be an owner of api_keys - and expect every ApiKey to have an owner. I would prefer to have a non-polymorphic association to take advantage of a foreign_key.
I assume in the gem's code base the owner is usually accessed over the activerecord association - meaning it would behave the same way for a polymorphic and non-polymorphic relationship in all(?) use cases. So probably having this configurable would be a smaller code change?
I'm not 100% sure what would be the best way to define the belongs_to relationship depending if the implementation uses polymorphic or not. What is your take on this?