Questions tagged [gorm]

1

votes
0

answer
14

Views

Gorm (Golang) and database with Single Table Inheritance “type” column

I'm experimenting with using Go to read from a database that's been part of an existing Rails app. A few of the models and therefore tables use single table inheritance via a type column. In Rails/ActiveRecord, the presence of this column will create an automatic mapping to the appropriate model. If...
subvertallchris
0

votes
0

answer
2

Views

How to save a domain with a hasMany property in gorm-hibernate

I have a User with hasMany UserRoles but when i try to save a User and addToRole there is a validation error during save i cant understand why. class User ... { static hasMany = [roles:UserRoles] } then i have a domain UserRoles class UserRoles ... { Roles role static belongsTo = [user: User] User...
Tarro Eso
1

votes
1

answer
99

Views

Setting domain class property values with GORM

After a user creates a record in my Grails application it takes that information and populates and displays a graph. The user can then click a button on that page and be redirected to the create page. When that happens I would like the previous data entered to be displayed as the defaults for those...
Sulteric
1

votes
2

answer
72

Views

Grails GORM - return count of objects who's array property > 0

Consider the following; class Person { int id String name static hasMany = [cars : Car] } class Car { int id String brand static belongsTo = Person static hasMany = [owners: Person] } The above will result in a person_cars join table. All I'm trying to find out is if there are any entries in that ta...
dre
1

votes
0

answer
69

Views

Gorm and associations

I'm trying to figure out how to load associations with gorm. The documentation is not that great. I have to models: type Account struct { gorm.Model Name string `gorm:'column:name;unique_index;not null;size:255'` AccountTypeID uint `gorm:'not null'` UserID uint `gorm:'not null'`...
Tino
1

votes
0

answer
713

Views

gorm.DB can't preload field currencies for model.Currency

I was looking through gorm.DB's docs and sources but can't seem to understand the purpose of Preload. I thought that is the 'preloaded schema/tables/rows' that you can use afterwards' but cannot somehow use it that way. For instance I have the following struct package model type Currency struct { ID...
Patryk
1

votes
0

answer
122

Views

Many to Many: Save and Update single struct not working

I'm trying to work with postgresql and gorm but I'm encountering the following problem. I have two structs (Tenantx,Userx) with a many2many relationship (this works) plus a field in each one (TenantAdmin,DefaultTenant) which relates to the other struct. Saving and Updating works with all fields exce...
Battalgazi
1

votes
1

answer
254

Views

How to construct subquery in the form of SELECT * FROM (<subquery>) ORDER BY column;?

I am using gorm to interact with a postgres database. I'm trying to ORDER BY a query that uses DISTINCT ON and this question documents how it's not that easy to do that. So I need to end up with a query in the form of SELECT * FROM () ORDER BY column; At first glance it looks like I need to use db.Q...
Corey Ogburn
1

votes
0

answer
99

Views

Error on inserting JSON in Go Gorm

I am working in Go using Gorm as 'ORM', I have a postgres database and I am trying to perform an update operation over one of the tables, the thing is that I have defined a JSON column and that column is giving me troubles to make the update. To generate that JSON I am using go simple json, I prin...
Sredny M Casanova
1

votes
0

answer
46

Views

Can associations in gorm go both ways?

Can I make associations in gorm go both ways? i.e. type Store struct { ID int Products []Product } type Product struct { ID int StoreID int Store Store } So a Store has many Products, and a Product belongs to a Store. Is this correct?
Blankman
1

votes
0

answer
44

Views

Retrieve deleted rows on deletion

Is there a way to retrieve the rows deleted when calling Delete()? I'd like to avoid using 'SELECT ... FOR UPDATE' to first get the list of rows I'm deleting. type MyModel struct { gorm.Model .... } res := db.Where('updated_at < ?', expirationDate). Set('gorm:save_associations', false). Delete(&MyMo...
lilorox
1

votes
0

answer
135

Views

How to prevent gorm from failing to save associations when UNIQUE constraint is violated?

I have the following struct type Category struct { gorm.Model Name string `gorm:'type:varchar(128);not null;unique'` } which is associated to Item struct: // Item is a type representing a job listing on stackoverflow jobs type Item struct { GUID string `gorm:'primary_key'` Link string Categories...
Patryk
1

votes
2

answer
255

Views

Grails upgrade from 2.4.5 to 3.3.2: Relation 'xxx' does not exist

is it required to do database migration for upgrading Grails 2.4.5 to 3.3.2 project. Currently, I m facing an issue in Bootstrap.groovy, application fails to start. ERROR: Relation 'department' does not exist org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not execute st...
user8125765
1

votes
1

answer
97

Views

Using multiple dataSources in Grails

I am using Grails 2.4.4. I am trying to configure multiple DataSources by following these Grails docs. Based on documentation I have added multiple dataSources in DataSource.groovy. Docs say that in domain classes I can specify dataSource by using following statement. static mapping = { datasource '...
ivish
1

votes
0

answer
29

Views

connecting to many distributed data bases in Grails 2.2.0

In our project we are using Grails 2.2.0 with Groovy . We have requirement One deployment multiple Database per country .Say if User belongs to US our Application will connect him to US data base when User belongs to UK our application will connect to UK Data base . Database are distributed data ba...
user9461817
1

votes
1

answer
73

Views

Generic ValueConverter

I'm trying to register a custom generic value converter but it's not being picked up in the binding process. What can be wrong. It's based on this manual: https://docs.grails.org/latest/guide/theWebLayer.html#dataBinding When I remove the generics everything works fine. my generic enum converter: ab...
Kuba
1

votes
1

answer
1.3k

Views

Golang's GORM not adding associations to “has many” relationship

I just started using GORM and tried to build a 'has many relationship'. I'm trying to add an association to Previous.Holdings (I think I followed the docs correctly) but when I try to do a select * from previous I don't see anything showing up in the database. Any idea on what I'm missing. import (...
jack sexton
1

votes
2

answer
88

Views

Joint queries through foreign key

I have the following two models: File and Session, and a single session could have many File objects (one-to-many). type Session struct { gorm.Model Name string `json:'name,omitempty'` IsCurrent bool `json:'is_current'` Files []File `gorm:'foreignkey:SessionID...
TonyGW
1

votes
1

answer
29

Views

Can I create a custom criteria query like

I have a legacy PostgreSql table that contains columns with multiple values. I want to select rows that contain any of the values in my search. -- Example query select * from stuff where ARRAY['Value A', 'Value X'] && regexp_split_to_array(thing, '\|'); Can I generate this type of where condition fr...
user1452701
1

votes
1

answer
310

Views

Grails Unit Test fails: String-based queries like [executeQuery] are currently not supported in this implementation of GORM

There are other questions on SO about this, but they are pretty old and none offer solutions to my issue. I'm getting the following error from a unit test: java.lang.UnsupportedOperationException: String-based queries like [executeQuery] are currently not supported in this implementation of GORM. Us...
beechovsky
1

votes
2

answer
95

Views

Grails 3 saving mongoDB document with both _id and id

We noticed an issue after an upgrade to grails 3 that we were saving mongoDB documents with both _id and id. (example document below) How do we stop the saving of id? This happens for every collection the application creates and updates documents for. { '_id' : ObjectId('5b0ed1b710b3641a98aaee63'),...
David B
1

votes
1

answer
123

Views

Grails Hibernate GORM, Multi-Tenancy with one-to-one relationship

Cloned the code from the tutorial : Database per Tenant Multi-Tenancy I went into the completed project and began playing around with things. I understand how the application is resolving tenant ids and connecting to varying datasources without difficulty. What is leaving me scratching my head is ho...
HumbleWebDev
1

votes
0

answer
144

Views

Postgres foreign key on delete constraint

Been following the guide on http://gorm.io/docs/belongs_to.html trying to get simple foreign keys setup, however, I can't find any info on using ON CASCADE or ON DELETE. On http://doc.gorm.io/database.html#migration under the Add Foreign Key section it does make use of ON DELETE and ON CASCADE, how...
Greg Miller
1

votes
0

answer
234

Views

gorm don't find a column field with quotes

Here is my code : package main import ( 'github.com/jinzhu/gorm' _ 'github.com/jinzhu/gorm/dialects/postgres' 'time' 'fmt' ) func (Rank) TableName() string { return 'Score_rank' } // Overriding Column Name type Rank struct { Id int64 `gorm:'column:id'` DateCreation time.Time `gorm:'column:...
user462794
1

votes
1

answer
63

Views

Grails GORM hasMany association inconsistent with MongoDB, When try to fetch child Records,it fetches the record sometimes and doesn't fetch sometimes

Below is the domain class Author which has a one-to-many association with Book. When trying to fetch Author, sometimes will get the associated collection of Book domain object and sometimes returns null. Any thoughts on why it is inconsistent? class Author { static mapWith = 'mongo' String name stat...
Mukesh Singh
1

votes
0

answer
35

Views

GORM is not persisting the changes of an object

I have a service class that is responsible for managing Project entity (simple things for now). @Transactional class ProjectService { UserService userService ... @Publisher(ProjectEvent.PROJECT_UPDATED) Project updateById(Long id, ProjectCommand command, Long updatedById) { User updatedBy = userServ...
1

votes
0

answer
24

Views

Restrict the execution of same GORM object in groovy

I' am new in groovy.in my project I get the data from db using GORM object. When Ever I call the object for data it execute multiple time.I have no Idea why it is executing. After getting the data using the same object when I see the hibernate log there is more then execution of the same object. for...
mohan
1

votes
2

answer
52

Views

Use dynamic finders with list of Object IDs

With the given class structure class MyObject { Status status; } class Status { Integer id; } I want to use dynamic finders to query based on a list of Status ID values. What I want to be able to do is something like this MyObject.findAllByStatusInList([1,2,3]); This does not work though because my...
Raymond Holguin
1

votes
0

answer
248

Views

MS SQL datetime representation in go-gorm

Title says it all. I'm using gorm (golang orm) to connect to a MS SQL db. time.Time gets me datetime2 which is a different dataType. Any suggestions? Structure: type ( ACDepartements struct { DEPTID int `gorm:'column:DEPTID;primary_key;not null;'` DEPTNAME string...
Trody
1

votes
2

answer
85

Views

GORM: Change of inherited field not isDirty()?

After modifying an inherited many-to-one relationship field the change cannot be detected using isDirty() or similar checks. How can I detect the change without manually checking the field? I have already attempted to use @DirtyCheck, however this only works for simple fields, such as lookupId. @Di...
bigfatony
1

votes
3

answer
341

Views

Grails 3.3.6 Does not come with GORM Configured?

I had to upgrade a grails plugin from 2.3.11 to 3.3.6. When I was testing the finished port I noticed errors on my GORM queries. If I recall, in grails 2 GORM already came with it. Is that not the case in grails 3.3.6 ? What do I need to do to enable GORM? I will mention that I am using a SQL Server...
Bmoe
1

votes
0

answer
83

Views

How does gorm determine which table to use?

I want connect to SQL SERVER using gorm. I've read documentation how to create new record in table. There is a code: user := User{Name: 'Jinzhu', Age: 18, Birthday: time.Now()} db.NewRecord(user) // => returns `true` as primary key is blank db.Create(&user) db.NewRecord(user) // => return `false` af...
1

votes
0

answer
112

Views

How to update the nested tables in sql using gorm?

Here the code is written in Go. I am using two tables where one table has a foreign key that refers to the other table's primary key. Let's say I have a database as following struct defined: type User struct{ ID uint `gorm:'primary_key;column:id'` Name string `gorm:'column:name'` Place place PlaceID...
manav Jain
1

votes
0

answer
33

Views

nested exception is org.hibernate.HibernateException: Missing column in GORM many to many mapping

The table is already created inside the database using another software, I need to convert the mapping with GORM, So the column name and type has already been created. Class Customer{ static hasMany = [ reservationClienti:ReservationSource] static mapping = { sort('id') table name: 'clienti'//, sche...
Madhvendra Thakur
1

votes
0

answer
56

Views

How do I stop GORM from sorting my preload by ID?

In my database I have a users table, joined via a many-to-many table to schools. A school has many jobs. I'm trying to return all the schools and their jobs for a specific user. This is my code so far: var user User err := db.Where('id = ?', userID).Preload('Schools') .Preload('Schools.Jobs', func(d...
LaserJesus
1

votes
1

answer
68

Views

MissingPropertyException in SpringSecurityService in my Grails 3.3.8 application

Using the grails spring security plugin (3.2.3) I have an app with the standard domain classes that are created using this guide: https://grails-plugins.github.io/grails-spring-security-core/3.2.x/index.html#tutorials It has the following classes specified in the tutorial: Role.groovy, UserRole.groo...
georgy3k
1

votes
0

answer
55

Views

Raw query not populating one-to-many association

I have the following sqlite query: SELECT orders.id , orders.shop_id , tv.total_value , line_items.id , line_items.product_id , line_items.order_id , line_items.description , line_items.quantity , products.price AS 'line_items.price' FROM orders JOIN line_items ON line_items.order_id = orders.id JOI...
Sean
1

votes
0

answer
29

Views

GORM createCriteria and the result set do not return the same results

In the createCriteria using max:50 and offset:0, I have a projection like below projections { sum('downloads') sum('clicks') groupProperty('site') groupProperty('link') groupProperty('device') } totalCount returns 939 rows and the result set returns 8. How I can get the no of resultset? I tried resu...
1

votes
1

answer
92

Views

Connect localhost Postgres database

I just installed for the first time Postgres on my computer and I was able to connect my database through JetBrains DataGrip. but when I am trying to connect the database through my app (using gorm) it doesn't work... jdbc:postgresql://localhost:5432/postgres and i did try to connect this way: postg...
Nir Berko
1

votes
1

answer
190

Views

Cant connect to postgres (password authentication failed for user - docker)

I was trying to run docker compose to set up nginx, golang server and postgresql. The problem is that I can't connect to the database: Initially, I was trying to connect to postgres with this instruction: db, err = gorm.Open('postgres', 'host=db port=5432 user=sigbrian password=example sslmode=disab...
Joaco Terniro

View additional questions