-
-
Notifications
You must be signed in to change notification settings - Fork 398
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
Inserting with relationships #478
Comments
Hi, This looks like a good idea, but it requires some work and time to get it done. I would appreciate any help, but unfortunately code that works with relations is rather complex and doesn't have any comments so you will have a tough time reading it. But here are some advices:
Then by iterating over relations you can start building your query using existing |
Perfect thank you! I had closed it because I saw there was a similar issue already open. |
Hi, any update on this issues? @vmihailenco |
Any updates on this? Thanks |
Would definitely appreciate support for this. Has any progress been made towards this feature? |
Looking forward for this |
Several times when inserting a model that has relationships we want to insert its relationships along with it. This is achievable in one query using just raw sql but then we lose all the advantages that
go-pg
offers. For example acompanies
andservices
table werecompanies
has-many
services
.And the sql tables would look smtn like this:
We can insert this in one query pretty easily with raw sql:
Now to do something similar using
go-pg
we would have to use thedb.Prepare
statement. Note the code may be ugly but serves the purpose to showgo-pg
support would be helpful.Now the problem with this besides how much work and different ways to go about this is we lose the null wrapper
go-pg
provides. Now for all my string instances or int instances I need to wrap them with a function to transform them to sql null values or use pointers for all my types (feels iffy). Which makes our code event uglierInstead it would be nice if when running
db.Insert
it could automatically check for struct arrays that usually means a table relationship and if its not null in the struct to insert all the relationships. Or maybe adding a newdb.InsertWithRelations()
method if adjustingdb.Insert()
would be to much work.As a side note I tried finding your email to send you a private message but couldn't find it so I'm gonna do it here. I've been using your package now for a few months and I love it I want to start contributing to it and was wondering if there was anything specifically you would like an extra hand with. Let me know and great job on a great package
The text was updated successfully, but these errors were encountered: