jinzhu / copier

Copier for golang, copy value from struct to struct and more
MIT License
5.58k stars 490 forks source link

is this does not copy embeded struct ? #6

Closed aliuygur closed 8 years ago

aliuygur commented 9 years ago

hi dear,

i have some struct like this

type BaseModel struct {
    ID        uint       `json:"id" gorm:"primary_key"`
    CreatedAt time.Time  `json:"createdAt"`
    UpdatedAt time.Time  `json:"updatedAt"`
    DeletedAt *time.Time `json:"deletedAt"`
}

// PostResource post resource
type PostResource struct {
    BaseModel
    Title       string `json:"title"`
    Description string `json:"description"`
    // Tags        []Tag  `json:"tags"`
}

// Post post model
type Post struct {
    BaseModel
    UserID      int    `json:"-"`
    ImageID     int    `json:"-"`
    TagID       int    `json:"-"`
    Hit         int    `json:"hit"`
    Title       string `json:"title"`
    Slug        string `json:"slug"`
    Description string `json:"description"`
    Body        string `json:"body"`
    User        User   `json:"user"`
    Tags        []Tag  `gorm:"many2many:pivot_tip_tag;"`
}

i am trying copy Post to PostResource, but the BaseModel fields(ID,CreatedAt,UpdatedAt,DeletedAt) not copying.

do you have any idea ?

kyleboyle commented 8 years ago

see: https://github.com/kyleboyle/copier/commit/1f8098de816eb8f0328a0f25771046968e64a099

dvdplm commented 8 years ago

@kyleboyle @jinzhu would be a great PR for copier! Any chance we can get it merged into main repo? :)

kyleboyle commented 8 years ago

sure I'll create one. I didn't do it yet because I saw an open PR from last year and assumed this project was inactive. But i was wrong :)