I have two existing models user
and permissions
. I would like to add one to many relationship to user
model. I have been digging all the internet and there seems to be no documented way to achieve the same. Would someone point me in the right direction on how to write the migration scripts to perform the same? Thanks
Asked
Active
Viewed 128 times
1

Muteshi
- 820
- 1
- 10
- 25
-
which table is one, which is many? I think you can use alter table add foreign constrain (found on postgres doc) – deko_39 May 11 '22 at 09:48
-
User is one, Permission is many. A user can have as many permissions as possible – Muteshi May 11 '22 at 09:52
-
ALTER TABLE public.permissions ADD COLUMN "userId" VARCHAR (255), ADD FOREIGN KEY ("userId") REFERENCES public.user (id); – deko_39 May 11 '22 at 10:00
-
Read more at: https://stackoverflow.com/questions/35676149/adding-a-column-as-a-foreign-key-gives-error-column-referenced-in-foreign-key-co – deko_39 May 11 '22 at 10:00
-
If you are using ORM, just use the way ORM suggest rather than this DSL query – deko_39 May 11 '22 at 10:01
-
Will this query create one to many relation? – Muteshi May 11 '22 at 12:46