User profile. I have some attributes that have only 2 or 3 options. For example I store gender in table as tinyint (male=1, female=2). So in table I have tinyint but in frontend I need to display string. I have about 4 attributes that have just about 2 options.
So I have two options how to display string from option:
Create extra table where all attribute options will be stored. But in this case I need to create for such a tiny thing everytime extra join.
Or I can put in profile_helper.php all functions for this kind of attributes. For example
function getGender($optionId){
$gender = $optionId == 1 ? "male" : "female";
return $gender;
}
Speaking about performance, is it worth to make extra join for such a small thing?
You could make your life easier and ENUM all of the possibilities, like so:
That way, you literally insert the values
'MALE'or'FEMALE'into the database, and when you retrieve the values from the database, you will get back one of those strings, and the only helper functions you may need isucfirst()orstrtolower().I would only recommend this approach for things that are highly unlikely to be changing (of which gender is a perfect example).