Skip to content

ORM PostgreSQL: Table name mismatch with module prefix #28106

Description

@Gako91

When using PostgreSQL ORM with structures in a module, the ORM automatically adds the module name as a table prefix (e.g., models.sendsmsrequest), but the table is created without this prefix (e.g., sendsmsrequest), causing an error during insert operations.

Reproduction code:

main.v:

module main
import orm
import db.pg
import models

fn main() {
	mut conn := pg.connect(pg.Config{host: "localhost", user: "user", port: 5439, password: "pass", dbname: "db"}, pg.PoolConfig{}) or { panic(err) }
	mut db := orm.new_db(conn, orm.DataScope{})
	sql db { create table models.SendSMSRequest } or { panic(err) }
	mut sms_send := models.SendSMSRequest{msisdn: "123456", msg: "Test", sender: "sender"}
	mut qb := orm.new_query[models.SendSMSRequest](db)
	qb.insert(sms_send) or { panic(err) }
}

models/models.v:

module models
pub struct SendSMSRequest {
	pub mut:
		id int @[primary; sql: serial]
		msisdn string
		msg string
		sender string
}

Expected behavior: The ORM should use the same table name for creation and insert operations.

Actual behavior:

  • Table created: sendsmsrequest
  • Insert attempted in: models.sendsmsrequest → Error "relation does not exist"

Environment:

  • V version: 0.5.2
  • OS: Linux
  • Database: PostgreSQL

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions