# Set\_belongs\_to\_association\_for

**URL:** <https://www.ruby-forum.com/t/set-belongs-to-association-for/126336>\
**Category:** Rails\
**Created:** [January 17, 2008, 3:05pm UTC](https://www.ruby-forum.com/t/set-belongs-to-association-for/126336 "2008-01-17T15:05:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 17, 2008, 3:05pm UTC](https://www.ruby-forum.com/t/set-belongs-to-association-for/126336/1 "2008-01-17T15:05:03Z")

</div>

I have a question on  
“ActiveRecord::Associations::AssociationProxy.set\_belongs\_to\_association\_for”  
it is a protected method.

```
    def set_belongs_to_association_for(record)
      if @reflection.options[:as]
        record["#{@reflection.options[:as]}_id"] = @owner.id

```

unless @owner.new\_record?  
record["#{@reflection.options[:as]}\_type"] =  
@owner.class.base\_class.name.to\_s  
else  
record[@reflection.primary\_key\_name] = @owner.id unless  
@owner.new\_record?  
end  
end

I was wondering why class.base\_name was used for the record type and  
not class.name?

Mehmet
