As part of my getting back on the rails train, I’ve decided to give TextMate another try as well. So far, so good. Im making a concerted effort to learn the ins & outs of it. I had been using RadRails, but it’s big, and rather slow at times. Also, it’s very obviously *NOT* a Cocoa application. It felt gratingly out of place.
TextMate truly is a nice editor.. it’s no big surprise it won an Apple design award at WWDC earlier this month.
Given my Emacs based “upbringing”, TextMate feels nice. I’m looking forward to getting to know this app well.
UPDATE: While TextMate is a sweet text editor, I’ve since decided that it is not the programming editor for me.. I’ve switched to GNU Emacs on OS X for that.
For anyone learning rails in my wake, here the “Doh!” moments I had as I tried to get many-to-many relationships working. Either it took some digging to find the required information or it wasn’t immediately obvious.
Here’s my list of things I found by trial/error/reading/ and lots of googling (and, yes, it is a verb now.. I’ve been using it as a verb for at least 3 years).
has_and_belongs_to_many in each class, naming the other class (it’s table name really… a plural)
- Add instances of one class to the collection in the other, e.g.
order.items << album. Do this in only one direction.
- Before adding to an object’s collection, save the object. E.g
order.items << an_item
It seems that this is only required in the case where
order is a freshly created object. This makes sense as it will not have an
id (for the join table) until it is saved. Furthermore, both objects will have to have been previously saved (i.e. have
- The join table is made up of the names of the two related tables.. in alphabetic order. E.g.
- Don’t put an id column in the join tables. Mine had such a column because I sketched out my schema in a migration, not realizing this.
- In your migrations, use
:id => false as a second argument to
create_table :items_orders, :id => false do |t|
t.column :item_id, :integer
t.column rder_id, :integer
If I’ve missed anything on this list, please let me know and I’ll add it.
My ramp up on Rails continues. Today I’ve been getting familiar with ActiveRecords table relationship facilities. Pretty nice. One-to-one and one-to-many were trivial… although I’m currently stuck on getting many-to-many relationship working. I keep making progress in little steps, though.