Skip to content
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

Simplify relation mapping between tables #6874

Open
daqiancode opened this issue Mar 6, 2024 · 1 comment
Open

Simplify relation mapping between tables #6874

daqiancode opened this issue Mar 6, 2024 · 1 comment
Assignees

Comments

@daqiancode
Copy link

daqiancode commented Mar 6, 2024

Describe the feature

Would please simplify the relation mapping between tables like SqlAlchemy.

for example:

class Collection(Base):
    __tablename__ = "collction"

    id = Column(Integer, primary_key=True, autoincrement=True)
    name= Column(String(100), nullable=False)

class Document(Base):
    __tablename__ = "document"

    id = Column(Integer, primary_key=True, autoincrement=True)
    # foreign key to collection
    document_id = Column(Integer , ForeignKey("collection.id", ondelete="CASCADE"))

Golang example:

type Collection struct {
	Base
	Name string `gorm:"type:varchar(100) not null" json:"name"`
}

type Document struct {
	Base
	DocumentId int64 `gorm:"type:bigint not null;fk:Collection.Id,ondelete=CASCADE" json:"documentId"`
}

Motivation

belong,one2one,one2many, many2many are useless on most cases and add much complexity to the project. Please let developers to build relations in the code.
Reasons:

  1. The records of tables are offen cache in the redis. It means one2one,one2many,many2many are no need.
  2. many2many is useless. The middle table offen has other column, and the middle table maybe has more than 2 foreigner keys.
  3. Please forget Java ORM in golang. be light.

Related Issues

@github-actions github-actions bot added the type:feature_request feature request label Mar 6, 2024
Copy link

github-actions bot commented Mar 2, 2025

This issue has been automatically marked as stale because it has been open 360 days with no activity. Remove stale label or comment or this will be closed in 180 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants