# Artificially setting an association?

**URL:** <https://www.ruby-forum.com/t/artificially-setting-an-association/138450>\
**Category:** Rails\
**Created:** [May 23, 2008, 6:39am UTC](https://www.ruby-forum.com/t/artificially-setting-an-association/138450 "2008-05-23T06:39:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_JSBott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ee7513/32.png) [@Christopher\_JSBott](https://www.ruby-forum.com/u/Christopher_JSBott)\
**Post date:** [May 23, 2008, 6:39am UTC](https://www.ruby-forum.com/t/artificially-setting-an-association/138450/1 "2008-05-23T06:39:34Z")

</div>

Hello. I want to be able to set what’s in an association without  
Rails trying to update the database.

Assume a Page has many Links.

I want to be able to say this…

page = Page.find :first  
links = Links.find :all, :conditions =\> [“page\_id != ?”, page.id]  
page.links = links

Without Rails trying to update the database and trying to set page\_id  
on all the records in links.

I wish it was as simple as saying…

page.instance\_variable\_set(’@links’, links)

but it’s not because links is an association proxy object.

Any ideas? Thanks.

---

<div class="post-metadata">

**Author:** ![Christopher\_JSBott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ee7513/32.png) [@Christopher\_JSBott](https://www.ruby-forum.com/u/Christopher_JSBott)\
**Post date:** [May 23, 2008, 7:02am UTC](https://www.ruby-forum.com/t/artificially-setting-an-association/138450/2 "2008-05-23T07:02:58Z")

</div>

On May 22, 11:39 pm, “Christopher J. Bottaro” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I want to be able to say this…
> 
> page = Page.find :first  
> links = Links.find :all, :conditions =\> [“page\_id != ?”, page.id]  
> page.links = links
> 
> Without Rails trying to update the database and trying to set page\_id  
> on all the records in links.

page.links.target = links

Use the source, Luke.
