Drop feeds/merge them into user
This commit is contained in:
parent
59373c6380
commit
f12059c760
13 changed files with 78 additions and 920 deletions
|
@ -30,7 +30,7 @@ func newNoteToFeed(db *gorm.DB, opts ...gen.DOOption) noteToFeed {
|
|||
_noteToFeed.ID = field.NewUint64(tableName, "id")
|
||||
_noteToFeed.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_noteToFeed.NoteId = field.NewString(tableName, "note_id")
|
||||
_noteToFeed.FeedId = field.NewUint64(tableName, "feed_id")
|
||||
_noteToFeed.ForUserId = field.NewString(tableName, "for_user_id")
|
||||
_noteToFeed.Reason = field.NewString(tableName, "reason")
|
||||
_noteToFeed.Note = noteToFeedBelongsToNote{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
@ -401,15 +401,10 @@ func newNoteToFeed(db *gorm.DB, opts ...gen.DOOption) noteToFeed {
|
|||
},
|
||||
}
|
||||
|
||||
_noteToFeed.Feed = noteToFeedBelongsToFeed{
|
||||
_noteToFeed.ForUser = noteToFeedBelongsToForUser{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Feed", "models.Feed"),
|
||||
Owner: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Feed.Owner", "models.User"),
|
||||
},
|
||||
RelationField: field.NewRelation("ForUser", "models.User"),
|
||||
}
|
||||
|
||||
_noteToFeed.fillFieldMap()
|
||||
|
@ -424,11 +419,11 @@ type noteToFeed struct {
|
|||
ID field.Uint64
|
||||
CreatedAt field.Time
|
||||
NoteId field.String
|
||||
FeedId field.Uint64
|
||||
ForUserId field.String
|
||||
Reason field.String
|
||||
Note noteToFeedBelongsToNote
|
||||
|
||||
Feed noteToFeedBelongsToFeed
|
||||
ForUser noteToFeedBelongsToForUser
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
@ -448,7 +443,7 @@ func (n *noteToFeed) updateTableName(table string) *noteToFeed {
|
|||
n.ID = field.NewUint64(table, "id")
|
||||
n.CreatedAt = field.NewTime(table, "created_at")
|
||||
n.NoteId = field.NewString(table, "note_id")
|
||||
n.FeedId = field.NewUint64(table, "feed_id")
|
||||
n.ForUserId = field.NewString(table, "for_user_id")
|
||||
n.Reason = field.NewString(table, "reason")
|
||||
|
||||
n.fillFieldMap()
|
||||
|
@ -470,7 +465,7 @@ func (n *noteToFeed) fillFieldMap() {
|
|||
n.fieldMap["id"] = n.ID
|
||||
n.fieldMap["created_at"] = n.CreatedAt
|
||||
n.fieldMap["note_id"] = n.NoteId
|
||||
n.fieldMap["feed_id"] = n.FeedId
|
||||
n.fieldMap["for_user_id"] = n.ForUserId
|
||||
n.fieldMap["reason"] = n.Reason
|
||||
|
||||
}
|
||||
|
@ -479,15 +474,15 @@ func (n noteToFeed) clone(db *gorm.DB) noteToFeed {
|
|||
n.noteToFeedDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
n.Note.db = db.Session(&gorm.Session{Initialized: true})
|
||||
n.Note.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
n.Feed.db = db.Session(&gorm.Session{Initialized: true})
|
||||
n.Feed.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
n.ForUser.db = db.Session(&gorm.Session{Initialized: true})
|
||||
n.ForUser.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
return n
|
||||
}
|
||||
|
||||
func (n noteToFeed) replaceDB(db *gorm.DB) noteToFeed {
|
||||
n.noteToFeedDo.ReplaceDB(db)
|
||||
n.Note.db = db.Session(&gorm.Session{})
|
||||
n.Feed.db = db.Session(&gorm.Session{})
|
||||
n.ForUser.db = db.Session(&gorm.Session{})
|
||||
return n
|
||||
}
|
||||
|
||||
|
@ -699,17 +694,13 @@ func (a noteToFeedBelongsToNoteTx) Unscoped() *noteToFeedBelongsToNoteTx {
|
|||
return &a
|
||||
}
|
||||
|
||||
type noteToFeedBelongsToFeed struct {
|
||||
type noteToFeedBelongsToForUser struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
|
||||
Owner struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
|
||||
func (a noteToFeedBelongsToFeed) Where(conds ...field.Expr) *noteToFeedBelongsToFeed {
|
||||
func (a noteToFeedBelongsToForUser) Where(conds ...field.Expr) *noteToFeedBelongsToForUser {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
@ -722,32 +713,32 @@ func (a noteToFeedBelongsToFeed) Where(conds ...field.Expr) *noteToFeedBelongsTo
|
|||
return &a
|
||||
}
|
||||
|
||||
func (a noteToFeedBelongsToFeed) WithContext(ctx context.Context) *noteToFeedBelongsToFeed {
|
||||
func (a noteToFeedBelongsToForUser) WithContext(ctx context.Context) *noteToFeedBelongsToForUser {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a noteToFeedBelongsToFeed) Session(session *gorm.Session) *noteToFeedBelongsToFeed {
|
||||
func (a noteToFeedBelongsToForUser) Session(session *gorm.Session) *noteToFeedBelongsToForUser {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a noteToFeedBelongsToFeed) Model(m *models.NoteToFeed) *noteToFeedBelongsToFeedTx {
|
||||
return ¬eToFeedBelongsToFeedTx{a.db.Model(m).Association(a.Name())}
|
||||
func (a noteToFeedBelongsToForUser) Model(m *models.NoteToFeed) *noteToFeedBelongsToForUserTx {
|
||||
return ¬eToFeedBelongsToForUserTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a noteToFeedBelongsToFeed) Unscoped() *noteToFeedBelongsToFeed {
|
||||
func (a noteToFeedBelongsToForUser) Unscoped() *noteToFeedBelongsToForUser {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type noteToFeedBelongsToFeedTx struct{ tx *gorm.Association }
|
||||
type noteToFeedBelongsToForUserTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a noteToFeedBelongsToFeedTx) Find() (result *models.Feed, err error) {
|
||||
func (a noteToFeedBelongsToForUserTx) Find() (result *models.User, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a noteToFeedBelongsToFeedTx) Append(values ...*models.Feed) (err error) {
|
||||
func (a noteToFeedBelongsToForUserTx) Append(values ...*models.User) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
|
@ -755,7 +746,7 @@ func (a noteToFeedBelongsToFeedTx) Append(values ...*models.Feed) (err error) {
|
|||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a noteToFeedBelongsToFeedTx) Replace(values ...*models.Feed) (err error) {
|
||||
func (a noteToFeedBelongsToForUserTx) Replace(values ...*models.User) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
|
@ -763,7 +754,7 @@ func (a noteToFeedBelongsToFeedTx) Replace(values ...*models.Feed) (err error) {
|
|||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a noteToFeedBelongsToFeedTx) Delete(values ...*models.Feed) (err error) {
|
||||
func (a noteToFeedBelongsToForUserTx) Delete(values ...*models.User) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
|
@ -771,15 +762,15 @@ func (a noteToFeedBelongsToFeedTx) Delete(values ...*models.Feed) (err error) {
|
|||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a noteToFeedBelongsToFeedTx) Clear() error {
|
||||
func (a noteToFeedBelongsToForUserTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a noteToFeedBelongsToFeedTx) Count() int64 {
|
||||
func (a noteToFeedBelongsToForUserTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a noteToFeedBelongsToFeedTx) Unscoped() *noteToFeedBelongsToFeedTx {
|
||||
func (a noteToFeedBelongsToForUserTx) Unscoped() *noteToFeedBelongsToForUserTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue