Skip to content

Non-polymorphic owners configurable?Β #1

@mediafinger

Description

@mediafinger

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 column

which 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_type

and the ApiKey class:

belongs_to :owner, polymorphic: true, optional: true

In 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions