How to deal with gender

Appreciate this is a path well travelled probably.

What’s the best way of to deal with gender.

i.e. a Person is either Male or Female (generally and fot my purposes
I’ll stick with that rule).

So is it best to go Person with an attribute gender, or, I guess it’s
best to do something like this - the rails way?

Person
belongs_to: gender

Gender
has_many: people

Sorry if this is such an obvious question just want to do it right.

Might just be me, but I’ve always thought of gender as an attribute of a
person in your context.

I’m not sure where a gender model comes into all of this, but you may be
thinking of something I’m not.

To populate from a static array or from AR… I had the same quandry
and
ended up doing it the ‘rails’ way as you describe below. Although as you
said, it is such a static thing that might as well use a constant array.
The
other question is to store M/F in Person.gender or store an integer.

Since rails should be caching the model, I dont think it is a real big
difference performance-wise either way. I think it probably comes down
to
your aesthetics, what feels right and what looks best to you.

Thanks chaps.

It’s now got me thinking. This stuff is not as easy as it looks. Ive
given up on gender when I realised that a name can belong to both
genders!

In English my app is a baby name chooser

A baby can have many proposed names but only one surname.

A name can be of many types, forename / middlename etc

Any tips how to model this!

David K. wrote:

To populate from a static array or from AR… I had the same quandry

According to the way I think, a model object is something you CURD
(create, update, read, or delete). Unless you’re God you’re not going to
be creating or deleting genders.

I’d go with a static enumeration (Male, Female or M, F or 0, 1). For the
sake of the “simplest solution that could possibly work,” I’d go with
Male/Female. No added complexity in having to format the data for the
view.

On Thu, 2010-07-29 at 19:01 +0200, Ar Chron wrote:

Might just be me, but I’ve always thought of gender as an attribute of a
person in your context.

It’s not just you.

How many types? I only see two types, “forname”, “middlename”. Are you
trying to build a baby name to put into a “shopping cart” of some sort?

I’m trying to develop an app where the full proposed baby name is kind
of built up by the user - i envisage some dragging and dropping to
reorder the firstnames - several combinations of “(forname +
middle(optional)) + surname” can be reordered to generate the final full
name and yes, I can only think that forname and middle name will be
necessary. Such a seemingly simple task but when I get to think about it
the options for the model seem endless!

Also, I don’t want to end up in ruby typing things like this.

name = Name.find_by_name(“some_name”) # seems ridiculous - too many
names.

grrr, maybe like this.

Baby
has_many :givennames

  • gender, string
  • surname, string

GivenName
belongs_to :baby

  • value, string
  • position, integer

So then I write stuff like

firstname = Baby.first.given_name.first
fullname = firstname + " " + Baby.first.surname

I’m not sure this all seems a bit clunky and maybe OTT. Not sure how to
arrange my models and attribs in this case. Is this approach
good/bad/ugly - really welcome some help as I’d like to get the model
right 1st off.

Are names generated by the user or do they see a list that you have
entered into the assumed database?

bingo bob wrote:

A name can be of many types, forename / middlename etc

Any tips how to model this!

The name itself should have “name”, “boys”, and “girls” where boys and
girls are booleans.

How many types? I only see two types, “forname”, “middlename”. Are you
trying to build a baby name to put into a “shopping cart” of some sort?


Alan G. - [email protected] - http://twitter.com/bigeasy

Hi Pale H.,

The names would be generated by the user, they are proposed new baby
names. The surname of the baby is of course fixed but needs to be
entered, it is that of the parents. Hope that makes sense.

Amazing how much there is to think about from a seemingly trivial job!

bb

So then I write stuff like

firstname = Baby.first.given_name.first
fullname = firstname + " " + Baby.first.surname

Sorry that code was wrong, I guess it would be something like…

firstname = Baby.first.given_name.first.value
fullname = firstname + " " + Baby.first.surname

I don’t like the “value” bit though, and I don’t want to do
given_name.name either. Any ideas.

bingo bob wrote:

The names would be generated by the user, they are proposed new baby
names. The surname of the baby is of course fixed but needs to be
entered, it is that of the parents. Hope that makes sense.

Amazing how much there is to think about from a seemingly trivial job!

Indeed, but I think you’re overcomplicating the issue.

bb

So, a simple form with the following fields:

Forename, Surname (both stored as strings). Two check boxes to
determine whether the name is for a male and/or female, and of course a
save button.

Present this form only after a User has logged in.

Now, a ProposedNames table with the following columns:

user_id:integer
forename:string
midname:string
surname:string
male:tinyint
female:tinyint

This allows Users to save their proposed names into a database for later
retrieval.

You can then give the view permission to re-order and alter these names
at any time, by displaying a list of proposed names to the User in a
secure area.

No validation on the column names are necessary, realistically.

Unless I’ve misunderstood your request, I don’t see any problems with
this approach.

bingo bob wrote:

Horseman.

Thanks for this.

Great.

But you can have multiple middle names!

An unlimited amount? In that case, you might consider storing the
entered forenames and middles names into separate tables and creating a
suggestion tool.

I recommend, taking a look at
#75 Complex Forms Part 3 - RailsCasts for adding other
fields dynamically.

An unlimited amount?

Well yes, I believe so. In the vast majority of cases people just have
firstname surname, also firstname middlename surname. But in essence
they could have 100 middle names; although it’s a little unlikely I
don’t believe there are legal constraints here in the UK.

Pragmatically though -
I think I’ll go with a minor adaptation(s) of your first solution…

ProposedNames table with the following columns:

user_id :integer
forename :string
midname1 :string
midname2 :string
midname3 :string
midname4 :string
midname5 :string
surname :string
gender :string

Really appreciate your other points re how I might handle the form and
logic. Got to love railscasts, I’d be nowhere without them, they are
truly excellent.

bingo bob wrote:

An unlimited amount?

Well yes, I believe so. In the vast majority of cases people just have
firstname surname, also firstname middlename surname. But in essence
they could have 100 middle names; although it’s a little unlikely I
don’t believe there are legal constraints here in the UK.

Pragmatically though -
I think I’ll go with a minor adaptation(s) of your first solution…

ProposedNames table with the following columns:

user_id :integer
forename :string
midname1 :string
midname2 :string
midname3 :string
midname4 :string
midname5 :string
surname :string
gender :string

Really appreciate your other points re how I might handle the form and
logic. Got to love railscasts, I’d be nowhere without them, they are
truly excellent.

I agree with your proposed structure. It would be my recommendation, but
you did specify ‘unlimited’.

It seems pointless for a human to have > 7 names.

Apologies for omitting the midname column from my original
recommendation.

I realised that it’s best to ignore the “one in a million” scenario, and
do what works in 99.9% of cases.

Horseman.

Thanks for this.

Great.

But you can have multiple middle names!

Annoying but true

Bb

bingo bob wrote:

I realised that it’s best to ignore the “one in a million” scenario, and
do what works in 99.9% of cases.

“All that is complex is not useful. All that is useful is simple.”

As I said in my initial reply, you were overcomplicating it.

Now if we could just stop thinking that the world is composed solely
of middle class white anglo saxon males and face the reality. Naming
conventions in some cultures go well beyond forename plus surname.
Those people also live in the UK.

I also note that you are omitting titles and suffixes such as “Queen
Elizabeth II” who is also called “Elizabeth Alexandra Mary Windsor”.
Or even “Hank Williams Jr” or “Hank WIlliams III” or “Sir Robert
Geldof”

Some people have only one name which is neither a forename or a surname.

Lets ignore the artist formerly known a Prince for a moment :slight_smile:

To be honest I would go with

user_id :integer
title :string
forename :string
midname :string
surname :string
suffixes :string
gender :string

and treat midname as a space separated list of names (although this
wont handle names like ‘st clair’ correctly).

Peter H. wrote:

I also note that you are omitting titles and suffixes such as “Queen
Elizabeth II” who is also called “Elizabeth Alexandra Mary Windsor”.
Or even “Hank Williams Jr” or “Hank WIlliams III” or “Sir Robert
Geldof”

Some people have only one name which is neither a forename or a surname.

Lets ignore the artist formerly known a Prince for a moment :slight_smile:

To be honest I would go with

user_id :integer
title :string
forename :string
midname :string
surname :string
suffixes :string
gender :string

and treat midname as a space separated list of names (although this
wont handle names like ‘st clair’ correctly).

I am sure the intended audience of this application would be content
with my proposal, but pursuing this argument is a waste of time and
resources.