mongoid/mongoid — comment on commit 216314d49fba340812a12efe071698baeef06f32
File:  line 0
By durran:

You need to add `:foreign_key => "parent-id"` with the dash in there instead of the underscore (Then you will see all the breakages). The problem is that we need to have both accessors for the aliased attribute name *and* the original attribute name, plus all the dirty accessors... (See https://github.com/mongoid/mongoid/issues/1571) No matter how you look at it something is going to break with that dash in there without using define_method. (And yes you are correct can only use #send in these cases, but Mongoid internally only uses send to do the auto-setting.)

The problem with underscore is it only handles the dash... If other special characters are in there then they are not covered and this blows up again, and there's an entire slew of unknowns around this that just sending the specialized stuff to define_method can cover for now...

In the future I may just not allow this since it's non-standard Ruby, and it's non-standard practice for field/column naming in database schemas (underscore is the norm)... I think given that the data is binary JSON in this case though it might be a bit of grey area... But my ultimate wish is that no one would name their fields like this and I could just prevent it completely. :)