# Mass Assginment and has\_many others.build

**URL:** <https://www.ruby-forum.com/t/mass-assginment-and-has-many-others-build/163656>\
**Category:** Rails\
**Created:** [March 23, 2009, 5:57pm UTC](https://www.ruby-forum.com/t/mass-assginment-and-has-many-others-build/163656 "2009-03-23T17:57:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [March 23, 2009, 5:57pm UTC](https://www.ruby-forum.com/t/mass-assginment-and-has-many-others-build/163656/1 "2009-03-23T17:57:07Z")

</div>

Typically, when one creates a has\_many associated table one does this:

hasone.hasmany.build({attribute hash},{attribute hash},…} or  
hasone.hasmany.create({attribute hash}, …

However, if mass assignment is turned off (attr\_accessible =\> nil), then  
I cannot seem to set the attributes directly.

For example, in a console session I do this:

> > me = Entity.new  
> > =\> …
> 
> > me.attribute = …  
> > …
> 
> > me.save!  
> > =\> true
> 
> > mi = me.identifiers.build  
> > =\> …
> 
> > mi.entity\_id  
> > =\> 1
> 
> > mi.identifier\_type = ‘post’  
> > =\> ‘post’
> 
> > mi.identifier\_type  
> > =\> nil

What is going on and how do I directly set association attributes?

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [March 23, 2009, 6:49pm UTC](https://www.ruby-forum.com/t/mass-assginment-and-has-many-others-build/163656/2 "2009-03-23T18:49:56Z")

</div>

Rails 2.3.2

This seems related specifically to the suffices \_type and \_value.  
Attributes ending in either of these strings are not processed by the  
attribute= method. if #write\_attribute(“something\_type”, “a value”) is  
called instead, then the somthing-type= method is again bypassed and the  
attribute is set to the literal value provided instead.

I have raised a ticket for this:

[http://rails.lighthouseapp.com/projects/8994/tickets/2314-v-232-appropriates-attributed-ending-in-\_type-and-\_value](http://rails.lighthouseapp.com/projects/8994/tickets/2314-v-232-appropriates-attributed-ending-in-_type-and-_value)
