# Overriding a Relationships Propertry

**URL:** <https://www.ruby-forum.com/t/overriding-a-relationships-propertry/166534>\
**Category:** Rails\
**Created:** [April 27, 2009, 1:58am UTC](https://www.ruby-forum.com/t/overriding-a-relationships-propertry/166534 "2009-04-27T01:58:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaggotChild](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ea924/32.png) [@MaggotChild](https://www.ruby-forum.com/u/MaggotChild)\
**Post date:** [April 27, 2009, 1:58am UTC](https://www.ruby-forum.com/t/overriding-a-relationships-propertry/166534/1 "2009-04-27T01:58:19Z")

</div>

I have a child relationship that is denormalized. I want to normalize  
it at the object level once it’s retrieved:

class Parent  
has\_many :denormalized\_children, :class\_name=\>‘Child’

def children  
if @normalized\_children.nil?  
@normalized\_children = []  
denormalized\_children.group\_by(&:number).each { |c|  
@normalized\_children \<\< NormalizedChild.new©  
}  
end  
@normalized\_children  
end  
end

This works fine, but I don’t want to eager load them  
as :denormalized\_children. I’d like to use :children. So I tried:

class Parent  
has\_many :children

alias :denormalized\_children :children  
def children  
#Same definition  
end  
end

AR doesn’t like this as it expects the children prop to return  
something that responds to loaded.

has\_many :children, :group=\>‘number’

doesnt work either since it discards all but N unique numbers. So if  
I have 10 with number 1 and 5 with number 2 I’ll only get back 2  
children.

Is there any way to do this without having to change the name of the  
relationship?

I can’t use after\_load (or whatever it’s called) in the Child class  
since the children need to be grouped by their relationship to their  
parent.

Any suggestions would be great.

Thanks
