Notes posted by foliosusRSS feed
Reply to tvle83 and pgmcgee: the destructiveness of this method depends on your database. Some databases are better at converting between disparate types than others. For example, when changing a column from a numeric type to a string type, some databases drop the data where others will turn the numbers into their string representations.
If you want to loop through the matches of a regular expression, String#scan is your friend. You can do something like this:
matches = '12345'.scan(/\d/) matches.each do |m| puts m end # => 1 # => 2 # => 3 # => 4 # => 5
Imagine the following
a has_many b b has_and_belongs_to_many c a has_many c :through => b
a.b works fine
b.c works fine
a.c throws an error!
ActiveRecord::HasManyThroughSourceAssociationMacroError: Invalid source reflection macro :has_and_belongs_to_many for has_many :stories, :through => :subcategories. Use :source to specify the source reflection
Specifying the source reflection still won’t help you though, because this kind of has_many :through isn’t supported at all.