Friday, July 27, 2007

has_many, finder_sql, and id

Jeez, has it been almost a month since my last post? Time flies when you're a lazy good for nothing.

Anyhow, since It took me some little while to track down this weirdness in rails, I thought I'd give back to the tribe and list the solution here too.

In Rails, you can specify model relationships with cool "macro" methods like 'has_many' and 'belongs_to'. If there is a fairly specific relationship you want to add to a model sometimes you may need to tell rails to just go ahead and use a query instead of the magic. Then you can specify 'finder_sql':


has_many :outstanding_invitations,
:class_name => 'FriendRecord',
:finder_sql => "select * from friend_records
where friend_id = #{id}
and invitation = true"


That's what I started with, but couldn't figure out why I wasn't getting what I wanted, and also getting a deprecation warning: "warning: Object#id will be deprecated; use Object#object_id". After a search I found this article, which has a good tip and the answer. The answer is that #{id} was being "expanded" once it was parsed, so by the time it got to the database it was already the object id, not the active record id. To fix, change the quotes to single quotes or use the %q quote delimiter to stop the id from being expanded.

Wednesday, June 20, 2007

Also see me at 360Flex

Come to 360 Flex! It should be great.

They were nice enough to ask me to speak, too.

I’m going to be talking about something I’ve had rattling around in my head for a while: Navigation and “power user” features in RIAs, specifically Flex RIAs. They way I use my computer is not the way I can use my RIAs, and I don’t like that. I use things like QuickSilver, and Firefox Mouse Gestures, and the command line (<3 bash)

The talk basically asks: How do you start introducing “power user” features into your Flex Apps, and how do you start to educate the general user about the productivity gains they’ll get by making use of these types of features?

I’m really excited about being able to do this talk. Plus, it means I get to go to 360 Flex. Good times.

See me at MAX

Hey all, and welcome to the brand new Hill of Beans 2.0, upgraded from 1.0 This is the first post. I hope you like it.

So, it's official! I'm confirmed as an Adobe MAX speaker, talking about the societal and physiological benefits of using Flex with Rails. The basic gist will be: unless you have some fairly complex enterprise use cases that cry for LiveCycle Data Services, or someone else is choosing your system back end and you have no say, you should be choosing Rails.

Rails values getting things done, and you'll feel how true that is to the very core of your being when you use it for the first time.

I'm excited to talk at MAX. What a great opportunity for a rookie speaker. I hope I can get some folks on board with using Rails and help get rid of this stupid stigma it seems is forming that Rails guys hate Flash. Silly. We'll fix it by getting Flex guys to love Rails and making more Rails guys that use Flex by this proven method.