-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
relationId issue #34
Comments
Please give more context, so I can try to reproduce it. Share what your state and country table classes look like. |
Well it's not specific to either table. It's any table any time you custom add the id as the primary key. Here's an address as an example.
So id is a varchar of 36 as that's the maximum possible length of a cuid. Once I add an
So it would throw an error if I tried to do |
I reproduced it, it's a bug, thank you for finding it! I'll do my best to fix it asap. The problem arises when |
It's fixed, update all orchid-related libraries to the latest version to get the fix. |
In regards to this, are there any future plans to add hooks to the tables? This way I could just add the createId() to a beforeCreate hook or something. |
Yes, I was thinking of supporting a JS-side callback in export class AddressTable extends BaseTable {
table = 'address'
columns = this.setColumns((t) => ({
id: t.varchar(36).primaryKey().default(() => createId()),
}))
} And it's possible to add a custom column type with predefined methods (in the BaseTable definition), so define once export class AddressTable extends BaseTable {
table = 'address'
columns = this.setColumns((t) => ({
id: t.id().primaryKey(),
}))
} And this override is currently possible in the ORM, but is yet to be handled in some way in the migrations. Anything useful goes to the todo list, I'll be grateful if you continue trying different things with it and find more room for improvement. |
Now it's possible to set the id in a export class AddressTable extends BaseTable {
table = 'address'
columns = this.setColumns((t) => ({
id: t.varchar(36).primaryKey().default(createId),
}))
} And all |
So just for my reference, this is just in the table definition, the migrations aren't aware of this yet, correct? |
Yes, so in a migration, it will be |
I'm using a cuid as the id instead of a serial or uuid, so I call this method
createId()
from@paralleldrive/cuid2
, and if I add that line, I am then unable to add a connection as just the id, I have to call a connect on the relation, for exampleas opposed to just setting
countryId: createdCountry.id
However, if I remove the id field, I can do this (it does not work as id is null, but typescript doesn't freak out).
Is this normal, expected behavior? And if so, why?
The text was updated successfully, but these errors were encountered: