Frederick Ros
2006-Apr-20 20:38 UTC
Associations misbehaviour when association name is CamelCased (ticket #4823)
Hi, I''m currently using Rails with a legacy database that uses it''s own naming conventions, one of them being that names are CamelCased. To be consistent I tried to CamelCase also my HABTM association names like: has_and_belongs_to_many :Roles However due to the current AR code and the way Ruby resolves symbols this fails. Currently the has_and_belongs_to_many :foo ends-up in creating 2 methods foo (reader returning an Array) and foo= (writer). Then we have some expressions like #{reflection.name}.clear, which are evaluated into foo.clear, and Ruby resolves foo as being a method, and everything is great. If I do define has_and_belongs_to_many :Roles, the 2 methods (Roles and Roles=) are created, and at some point Ruby tries to evaluate some code like Roles.clear, which fails as Roles is considered as a constant and no Roles constant is existing. IMHO, this can be easily fixed by prepending a self to the #{reflection.name} for example, and this is what is done in the patch attached to ticket #4823. Best Regards, -- Frederick Ros aka Sleeper -- sleeper@jabber.fr "All language designers are arrogant. Goes with the territory..." (By Larry Wall) _______________________________________________ Rails-core mailing list Rails-core@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-core
Frederick Ros
2006-Apr-21 19:28 UTC
Re: Associations misbehaviour when association name is CamelCased (ticket #4823)
Frederick Ros wrote : | Hi, | | I''m currently using Rails with a legacy database that uses it''s own | naming conventions, one of them being that names are CamelCased. | | To be consistent I tried to CamelCase also my HABTM association names | like: | | has_and_belongs_to_many :Roles | | However due to the current AR code and the way Ruby resolves symbols | this fails. | Currently the has_and_belongs_to_many :foo ends-up in creating 2 | methods foo (reader returning an Array) and foo= (writer). Then we have | some expressions like #{reflection.name}.clear, which are evaluated into | foo.clear, and Ruby resolves foo as being a method, and everything is | great. | | If I do define has_and_belongs_to_many :Roles, the 2 methods (Roles and | Roles=) are created, and at some point Ruby tries to evaluate some code | like Roles.clear, which fails as Roles is considered as a constant and | no Roles constant is existing. | | IMHO, this can be easily fixed by prepending a self to the | #{reflection.name} for example, and this is what is done in the patch | attached to ticket #4823. | Incidentally, is there any way to edit a ticket ? I''ve made a typo in my email address and I do not receive any (possible) update of this ticket. Best Regards, -- Frederick Ros aka Sleeper -- sleeper@jabber.fr Watch out for off-by-one errors. - The Elements of Programming Style (Kernighan & Plaugher) _______________________________________________ Rails-core mailing list Rails-core@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-core