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

NewStruct() reform.Struct #19

Closed
eaglemoor opened this issue Jun 6, 2016 · 4 comments
Closed

NewStruct() reform.Struct #19

eaglemoor opened this issue Jun 6, 2016 · 4 comments
Labels

Comments

@eaglemoor
Copy link
Contributor

Why NewStruct return reform.Struct if we have our struct, which implement reform.Struct?

https://github.com/AlekSi/reform/blob/master/reform/template.go#L45

@AlekSi AlekSi added the question label Jun 6, 2016
@AlekSi
Copy link
Member

AlekSi commented Jun 6, 2016

Because NewStruct() *Foo doesn't match signature NewStruct() reform.Struct, therefor *FooTable will not implement reform.View interface.

@AlekSi AlekSi closed this as completed Jun 6, 2016
@eaglemoor
Copy link
Contributor Author

I think that a particular table or twist must return a specific model, rather than an abstract. This is logical and convenient for the further use of this structure.

// foo is Foo, not reform.Struct
foo := FooView.NewStruct()

func useFoo(f Foo) {
}

@AlekSi
Copy link
Member

AlekSi commented Jun 6, 2016

It will not work in Go. For example, see https://github.com/AlekSi/reform/blob/master/querier_selects.go#L67 Here we need reform.View, and *FooView will not implement it (see my previous comment).

In you case you need this:

var foo Foo

That's it, no need to use NewStruct().

@eaglemoor
Copy link
Contributor Author

Thanks

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

No branches or pull requests

2 participants