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

Polymorphic table references #3359

Open
Meryldominguez opened this issue Nov 28, 2024 · 1 comment
Open

Polymorphic table references #3359

Meryldominguez opened this issue Nov 28, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@Meryldominguez
Copy link

Hello all! Apologies if this solution exists, I am rather new to flutter/dart/drift and still learning a ton.

I am trying to implement a polymorphic Tags table, and cannot find anything in the docs to suggest that is possible.

Ideally It could look something like this?

@TableIndex(name: 'tags_name', columns: {#name})
class Tags extends Table with Timestamps, AutoIncrementingPrimaryKey{

  TextColumn get name => text().withLength(min: 6, max: 32)();
}

class TagItem extends Table with Timestamps, AutoIncrementingPrimaryKey{
  IntColumn get tagId =>
      integer().nullable().references(Tags, #id)();
  IntColumn get itemId =>
      integer().nullable().references([Composers, People, Events], [#id, #id, #id])();
}

Is this in the works? already supported?

@Meryldominguez Meryldominguez added the enhancement New feature or request label Nov 28, 2024
@simolus3
Copy link
Owner

There is no support for polymorphic relations between tables in drift. So you would have to manually add a "type" column to TagItem to describe whether the item references composers, people or events. That also means that you can't rely on the foreign key capabilities of sqlite3 for that reference.

I haven't heard of this feature before and I couldn't find too many other database libraries supporting it either. I'm not sure if drift should support this given that it's not supported by databases and requires rewriting queries at runtime.

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

No branches or pull requests

2 participants