Reputation: 1182
I need to store integer and string values in one field. What type should I use in mapping? When I use string, I get integer values as string in my mongo documents.
Upvotes: 1
Views: 1628
Reputation: 71
Just use @ODM/Field(type="raw")
annotation :
https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/basic-mapping.html#doctrine-mapping-types
/**
* @ODM/Field(type="raw")
*/
protected $value;
Upvotes: 2
Reputation: 2790
Use the string mapping. Then in your getter for the field if you need to return different types. Use something like this
public function getTransgenderField() {
if (is_numeric($this->transgenderField)) {
return (int) $this->transgenderField;
}
return $this->transgenderField;
}
Upvotes: 0