|
Subject: Re: #3005 - Prevent duplicate names Newsgroups: gmane.comp.lang.ruby.rails.core Date: 2005-12-07 02:07:53 GMT (2 years, 37 weeks, 6 days, 17 hours and 32 minutes ago) Hi ! 2005/12/5, Michael Koziarski <michael <at> koziarski.com>: > On 12/6/05, Francois Beausoleil <francois.beausoleil <at> gmail.com> wrote: > > Hello all, > > > > I'd like to get a review of ticket #3005: http://dev.rubyonrails.org/ticket/3005 > > I like the general approach, How feasible is it to expand the > approach to handle columns called quote? I implemented it, but I don't like it... Here's a taste of what the new code returns: ./script/../config/../vendor/rails/railties/lib/commands/runner.rb:27: Columns 'name', 'transaction', 'quote' have already been taken in models of class Game. You will have to rename your columns to not conflict with pre-existing method names. (ActiveRecord::ColumnNameAlreadyTaken) When I used name in my models, I never expected that to conflict. It's such a common one. Guess what it conflicts with: Class::name. Here's the implementation of the guard method: # Raise ActiveRecord::ColumnNameAlreadyTaken if one of the columns defined # in objects of this class conflict with pre-existing method names. def guard_against_duplicate_column_names # We cast a very wide net here, maybe we should not cast such as wide one ? methods = [ ActiveRecord::Base.methods, ActiveRecord::Base.instance_methods].flatten.compact.uniq duplicates = self.class.columns.select do |column| next false if column.name == self.class.primary_key methods.include?(column.name) end raise ActiveRecord::ColumnNameAlreadyTaken.new(duplicates, self.class) unless duplicates.empty? end Thoughts anyone ? -- François Beausoleil http://blog.teksol.info/ _______________________________________________ Rails-core mailing list Rails-core <at> lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-core |
|
|