James Wilding's Weblog

Month: November, 2009

has_one vs. belongs_to in Rails

Which to use? Consider your pets.

If I own a dog, round his neck is a tag with my name on. The tag is like the dog’s owner_id: I have_one dog, and the dog belongs_to me.

If the dog owned me, I’d have a tag round my neck with the dog’s name on. This would be crazy, but my tag would be my dog_id: the dog would have_one :person, and I’d belong_to my dog.

The question of whether to use has_one or belongs_to is a matter of database columns. If your Dogs table has an owner_id column, then Dog.belongs_to :owner. If your People table has a dog_id column then, unnatural though it is, Person.belongs_to :dog and Dog.has_one :person.

Learn to love your canine overlord :-)

Why Britain should celebrate Thanksgiving

Bear with me here, because it’s not as crazy an idea as you’d think.

I have friends from the US, so I’ve been reading up about Thanksgiving lately (my previous understanding of this important cultural event is based on various episodes of Friends). Aside from the fact that we don’t have any pilgrim fathers to celebrate — apart from the ones who desperately wanted to leave our country — I think Thanksgiving would fit pretty well into British culture.

Exhibit A: Food

The British love their food almost as much as they love dogs and crazy-intelligent celebrities. So what could be better than another holiday where we get to cook vast amounts of food and then sit down to eat about half of it (the rest goes to the dog/cat/mad relative in the attic).

This from the Wikipedia article on Thanksgiving:

Firstly, baked or roasted turkey is usually the featured item on any Thanksgiving feast table (so much so that Thanksgiving is sometimes referred to as “Turkey Day”). Stuffing, mashed potatoes with gravy, sweet potatoes, cranberry sauce, sweet corn, other fall vegetables, and pumpkin pie are commonly associated with Thanksgiving dinner.

Sounds tasty, yes? Thanksgiving is towards the end of November, which would lets us gorge ourselves and then spend a good month recovering in time for Christmas.

(Vegetarians aren’t left out: they get Tofurky, “a meatless turkey made of tofu”. Mmm.)

Exhibit B: The Calendar

Winter in Britain is, let’s face it, pretty miserable. Autumn is gorgeous, then we have about five months on non-descript grey clouds and rain until spring. It’s not cold enough for snow (which is beautiful when done properly, as long as you’re inside), and not warm enough to be pleasant.

All of which means that we need a good set of winter festivals to see us through the dark months. Halloween kicks things off, followed by bonfire night (when we celebrate the burning to death of a guy who couldn’t come up with a convincing alias: yay! tradition!).

And then… two full months of nothing until Christmas. This is where Thanksgiving would fit in nicely, as a late-November pick-me-up to see us through until the end of December. I’m almost 100% sure that this would improve the national mood, and retailers would love it (“Thanksgiving turkeys, half price!!”).

Speaking of retail…

Exhibit C: Shopping

Last and by no means least, we come to my least-favourite aspect of winter in Britain: the Christmas shopping that starts in min-August. According to Wikipedia:

The American Christmas season traditionally begins the day after Thanksgiving.

Sounds great. We adopt Thanksgiving and make it a rule that Tesco can’t advertise crackers until after the fourth Thursday in November. As a consolation, they get to blast us with adverts for Thanksgiving turkeys all through September and October, but at least those ads will be more relevant to something close at hand.

Judgement

My personal opinion, based on, oh, five minutes of research and another ten minutes thinking (when I should have been working): Britain should find a reason to adopt Thanksgiving immediately (there’s still time to buy a turkey for tonight). In the absence of any other good excuse, maybe we can use it as a time to celebrate the fact that the puritans wanted to leave us the first place…