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

Slices always viewed as relations #5

Closed
uzarubin opened this issue Jan 18, 2017 · 3 comments
Closed

Slices always viewed as relations #5

uzarubin opened this issue Jan 18, 2017 · 3 comments
Labels

Comments

@uzarubin
Copy link
Contributor

uzarubin commented Jan 18, 2017

Hello there,

I was wondering if there is a possible bug with how the relation tag is handled. I have an Email model that holds the sender's email and a slice of recipients. I only want to store the recipient's email, and not the entire user object. The model is written as follows:

type Email struct {
	mongodm.DocumentBase `json:",inline" bson:",inline"`
	From	string `json:"from" bson:"from"`
	To 	[]string `json:"to" bson:"to"`
}

I am failing validation on the To field with validation.field_invalid_relation1n . Looking through the document_base.go file I found the following code:

if fieldValue.Kind() == reflect.Slice && relationTag != REL_1N {
  self.AppendError(&validationErrors, L("validation.field_invalid_relation1n", validationName))
} else if fieldValue.Kind() != reflect.Slice && relationTag == REL_1N {
  self.AppendError(&validationErrors, L("validation.field_invalid_relation11", validationName))
}

Shouldn't there be another check inside the if block to see if relationTag != ""? Without it, every slice would have to be a relation even though it doesn't need to be.

@moehlone
Copy link
Contributor

I will look into this in the next days, thank you!

@moehlone
Copy link
Contributor

You were absolutely correct. Thank you :) I put that case also in the tests.

@uzarubin
Copy link
Contributor Author

uzarubin commented Feb 3, 2017

Awesome! Thanks for taking care of it. : )

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