Artificially setting an association?

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.

On May 22, 11:39 pm, “Christopher J. Bottaro” [email protected]
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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs