Comments (8)
Hello @cursey,
You're right, right now this one is hard-coded, but should support an override.
In the meanwhile, you can use Where
instead, since Find
is mostly a WHERE id = ?
and a First
to get the only row.
from pop.
from pop.
@markbates @stanislas-m Some strategy needs to be laid out for these id mapping issues.
Are they going to be done individually or all in a single enhancement?
I can see pros and cons of both.
Too many changes at once is risky.
On the other hand, if would be confusing and possibly breaking for users who have models that map their ID field for the query but it isn't for the associations.
Also, we need a better test coverage of the associations.
from pop.
I am using postgres and I am getting the pq: column "id" does not exist
. The following is my model:
type SellOrder struct {
ID uuid.UUID `json:"seller_order_id" db:"seller_order_id"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
Quantity float64 `json:"quantity" db:"quantity"`
}
I have tried using the db
tag to specify the correct column name however I dont think the tag is taken into consideration.
from pop.
@nithin-bose No, the tag on the ID is not taken into consideration. It is hardcoded currently.
from pop.
Some strategy needs to be laid out for these id mapping issues.
Are they going to be done individually or all in a single enhancement?
I'd vote for a primary_key
struct tag that can override defaults. That way it could be set in one place instead of using that in every Find. It could also hlp with migrations generation (is it a feature?)
On the other hand, if would be confusing and possibly breaking for users who have models that map their ID field for the query but it isn't for the associations.
Could you elaborate @petar-dambovaliev ?
from pop.
Hi there
As pop documentation`s IDField :
/* pop/model.go:55 */
// IDField returns the name of the DB field used for the ID.
// By default, it will return "id".
func (m *Model) IDField() string {
field, ok := reflect.TypeOf(m.Value).Elem().FieldByName("ID")
if !ok {
return "id"
}
dbField := field.Tag.Get("db")
if dbField == "" {
return "id"
}
return dbField
}
It would respect Db design BUT what I found in codes pop/dialect_postgresql.go:60:
/* pop/dialect_postgresql.go:60 */
if len(w.Cols) > 0 {
query = fmt.Sprintf("INSERT INTO %s (%s) VALUES (%s) returning id", p.Quote(model.TableName()), w.QuotedString(p), w.SymbolizedString())
} else {
query = fmt.Sprintf("INSERT INTO %s DEFAULT VALUES returning id", p.Quote(model.TableName()))
}
BUT SHOULD BE: ... returning %s", p.Quote(model.TableName()), p.Quote(model.IDField())...
if len(w.Cols) > 0 {
query = fmt.Sprintf("INSERT INTO %s (%s) VALUES (%s) returning %s", p.Quote(model.TableName()), w.QuotedString(p), w.SymbolizedString(), p.Quote(model.IDField()))
} else {
query = fmt.Sprintf("INSERT INTO %s DEFAULT VALUES returning %s", p.Quote(model.TableName()), p.Quote(model.IDField()))
}
Not event "dialect_postgresql.go" but:
dialect_postgresql.go:61: query = fmt.Sprintf("INSERT INTO %s (%s) VALUES (%s) returning id", p.Quote(model.TableName()), w.QuotedString(p), w.SymbolizedString())
dialect_postgresql.go:63: query = fmt.Sprintf("INSERT INTO %s DEFAULT VALUES returning id", p.Quote(model.TableName()))
dialect_cockroach.go:75: query = fmt.Sprintf("INSERT INTO %s (%s) VALUES (%s) returning id", p.Quote(model.TableName()), w.QuotedString(p), w.SymbolizedString())
dialect_cockroach.go:77: query = fmt.Sprintf("INSERT INTO %s DEFAULT VALUES returning id", p.Quote(model.TableName()))
Anyone can do a favor to me, and tell me how to change them locally till these updates done?
from pop.
After some googling finally found that (git init, git add .) able me to change files!
I can confirm that the above code (my previous comment) works as expected!
This will works:
type SellOrder struct {
ID uuid.UUID `json:"seller_order_id" db:"seller_order_id"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
Quantity float64 `json:"quantity" db:"quantity"`
}
from pop.
Related Issues (20)
- feature proposal: add support to oracle DB HOT 1
- bug: transaction panic recovery swallows panic message HOT 3
- feature: log transaction/connection ID to track SQL executions for a request
- feature: Read/Write routing to different endpoints HOT 2
- feature: improve performance if the element of the Value of *Model does not implement the AfterFindable interface. HOT 4
- bug: DB connection locks up under load calling DB.Create(), regression in 6.1.0 vs 6.0.8 HOT 8
- feature: parallelize association loading HOT 2
- process: update supported database versions
- bug: sqlite3 testing on Windows + go 1.17 failing sometimes HOT 3
- bug: incorrect error handling
- Need a way to update stale pop connecton configs before pop reconnections a failed connectionfeature: HOT 6
- feature: upgrade jackc/pgx to v5 HOT 2
- feature: Dialect for Cassandra HOT 3
- feature: DB connection timeout HOT 2
- bug: "cannot parse UUID" on models.DB.Create HOT 1
- feature: context plumbing HOT 2
- bug: SQL connection leak when using EagerPreload HOT 4
- Slack Channel Not Working HOT 3
- is this project dead? HOT 5
- bug: Need to wrap error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pop.