> For the complete documentation index, see [llms.txt](https://doorkeeper.gitbook.io/guides/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doorkeeper.gitbook.io/guides/ruby-on-rails/polymorphic-resource-owner.md).

# Polymorphic Resource Owner

Enables polymorphic Resource Owner feature for Doorkeeper Access Tokens & Grants. By default Doorkeeper set only `resource_owner_id` without knowing model name of the Resource Owner.

Feature available only starting from Doorkeeper 5.4.

### How to use it

Enable configuration option:

{% tabs %}
{% tab title="config/initializers/doorkeeper.rb" %}

```ruby
Doorkeeper.configure do
  orm :active_record

  use_polymorphic_resource_owner
end
```

{% endtab %}
{% endtabs %}

Generate migration to add polymorphic columns to tables:

```bash
$ bundle exec rails g doorkeeper:enable_polymorphic_resource_owner
```

If you previously set foreign key for `:resource_owner_id` column - you need to drop it as now it would be a polymorphic association. You can drop FK in the migration generated above.

Run the migration:

```bash
$ bundle exec rails db:migrate
```

Use the feature!

Now you can access resource owner by `doorkeeper_token.resource_owner` association.

:warning: :warning: **\[ATTENTION]**: If you enabled this option on existing project - you need to manually set polymorphic type column with the class of the Resource Owner. Otherwise your existing users/clients could face issues and spam you logs with errors.

:warning: :warning: **\[ATTENTION]**: Also this feature could be a breaking change for those users that patched Doorkeeper internals, specially models. You need to fix your patches to user `resource_owner` instance instead of it's ID (like it was before).

## Known projects affected

* GitLab (<https://gitlab.com/gitlab-org/gitlab-foss/blob/master/config/initializers/doorkeeper.rb#L129>)
* Doorkeeper ORM extensions

Original PR: <https://github.com/doorkeeper-gem/doorkeeper/pull/1355>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://doorkeeper.gitbook.io/guides/ruby-on-rails/polymorphic-resource-owner.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
