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

Structure embedding and modelling #9

Closed
rahulkmr opened this issue Nov 6, 2012 · 4 comments
Closed

Structure embedding and modelling #9

rahulkmr opened this issue Nov 6, 2012 · 4 comments

Comments

@rahulkmr
Copy link

rahulkmr commented Nov 6, 2012

type Base struct {
    Created int64   `db:"created"`
    Updated int64   `db:"updated"`
}

func (b *Base) PreInsert(s gorp.SqlExecutor) error {
    b.Created = time.Now().UnixNano()
    b.Updated = b.Created
    return nil
}

func (b *Base) PreUpdate(s gorp.SqlExecutor) error {
    b.Updated = time.Now().UnixNano()
    return nil
}

type Post struct {
    Id int  `db:"id"`
    Name string `db:"name"`
    Title string    `db:"title"`
    Content string  `db:"content"`
    *Base
}


dbmap.createTables creates Post table with a member Base varchar(255). Does gorp support embedding structs? If yes, how do I do it?

@coopernurse
Copy link
Contributor

Hi there,

It doesn't support embedding yet, but it's a worthy enhancement. I'll keep this ticket open.

thanks.

@ottob
Copy link
Contributor

ottob commented Apr 1, 2013

+1

@sqs
Copy link
Contributor

sqs commented May 22, 2013

FYI, I have submitted a pull request that implements support for embedded structs: https://github.com/coopernurse/gorp/pull/42

@coopernurse
Copy link
Contributor

Yep, this was merged. Closing this ticket.

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

4 participants