The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Small ActiveRecord STI Gotcha

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Obie Fernandez

Posts: 608
Nickname: obie
Registered: Aug, 2005

Obie Fernandez is a Technologist for ThoughtWorks
Small ActiveRecord STI Gotcha Posted: Sep 7, 2005 10:11 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Obie Fernandez.
Original Post: Small ActiveRecord STI Gotcha
Feed Title: Obie On Rails (Has It Been 9 Years Already?)
Feed URL: http://jroller.com/obie/feed/entries/rss
Feed Description: Obie Fernandez talks about life as a technologist, mostly as ramblings about software development and consulting. Nowadays it's pretty much all about Ruby and Ruby on Rails.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Obie Fernandez
Latest Posts From Obie On Rails (Has It Been 9 Years Already?)

Advertisement

Discovered and submitted a Ruby on Rails bug today. The 'type' column on your ActiveRecord table is used by Rails magically to do single-table inheritance. You must make sure that the type column is wide enough to hold the longest subclass name or you'll run into a nasty little bug.

My table had its type column defined as VARCHAR(32). One of the subclasses is named ProductSpecificationQualityAttribute, 36 characters!!! Unfortunately, Rails didn't pick up on this little problem and stored new instances with a truncated type of ProductSpecificationQualityAttri, meaning that they do not appear in query results when you try to load them back in again from the db. Doh!

An exception would be much better in this case, so adjustments can be made to the db. It took me some time to track down the problem here because my database front-end (Navicat) was only showing about half of the width of the type column, so it wasn't obvious that the values in there were being truncated.

Read: Small ActiveRecord STI Gotcha

Topic: IMG_0709.JPG [Flickr] Previous Topic   Next Topic Topic: IMG_0706.JPG [Flickr]

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use