# Is "target" a reserved word?

**URL:** <https://www.ruby-forum.com/t/is-target-a-reserved-word/93989>\
**Category:** Rails\
**Created:** [April 17, 2006, 6:28pm UTC](https://www.ruby-forum.com/t/is-target-a-reserved-word/93989 "2006-04-17T18:28:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josh\_on\_Rails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/df705f/32.png) [@Josh\_on\_Rails](https://www.ruby-forum.com/u/Josh_on_Rails)\
**Post date:** [April 17, 2006, 6:28pm UTC](https://www.ruby-forum.com/t/is-target-a-reserved-word/93989/1 "2006-04-17T18:28:56Z")

</div>

I’m working on a cost estimation tool, that allows each estimate created  
to  
override base assumptions of price, cost, etc.

Everything was fine, until we said, “Let’s add a ‘target net revenue’  
property.”

So, the resource model got a “target” column. The override model got a  
“new\_target” column.

But, whenever I set resource.target, I don’t get a resource at the end;  
I  
get target. In other words:

old\_resource = resource.clone  
resource.target = new\_target  
resource == old\_resource # false  
resource == new\_target # true

---

<div class="post-metadata">

**Author:** ![Josh\_on\_Rails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/df705f/32.png) [@Josh\_on\_Rails](https://www.ruby-forum.com/u/Josh_on_Rails)\
**Post date:** [April 17, 2006, 7:54pm UTC](https://www.ruby-forum.com/t/is-target-a-reserved-word/93989/2 "2006-04-17T19:54:42Z")

</div>

Josh on Rails wrote:

> I’m working on a cost estimation tool, that allows each estimate created  
> to override base assumptions of price, cost, etc.
> 
> Everything was fine, until we said, “Let’s add a ‘target net revenue’ property.”
> 
> So, the resource model got a “target” column. The override model got a  
> “new\_target” column.
> 
> But, whenever I set resource.target, I don’t get a resource at the end;  
> I get target. In other words:
> 
> old\_resource = resource.clone  
> resource.target = new\_target  
> resource == old\_resource # false  
> resource == new\_target # true

“target” is a method on AssociationProxy, which is the parent of the  
class that implements the “resource” association attribute on your  
model. resource.target is the associated object itself, not its resource  
attribute! I spent part of the weekend delving into that code, and I  
think the proxy methods should all have names that start with “proxy\_”  
to avoid those sorts of collisions. Or at least be documented!

–  
Josh S.  
[http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)

---

<div class="post-metadata">

**Author:** ![Josh\_on\_Rails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/df705f/32.png) [@Josh\_on\_Rails](https://www.ruby-forum.com/u/Josh_on_Rails)\
**Post date:** [April 17, 2006, 10:44pm UTC](https://www.ruby-forum.com/t/is-target-a-reserved-word/93989/3 "2006-04-17T22:44:41Z")

</div>

I opened a ticket for this issue:  
[http://dev.rubyonrails.org/ticket/4769](http://dev.rubyonrails.org/ticket/4769)

–  
Josh S.  
[http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)

---

<div class="post-metadata">

**Author:** ![Josh\_on\_Rails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/df705f/32.png) [@Josh\_on\_Rails](https://www.ruby-forum.com/u/Josh_on_Rails)\
**Post date:** [June 20, 2007, 1:20am UTC](https://www.ruby-forum.com/t/is-target-a-reserved-word/93989/4 "2007-06-20T01:20:20Z")

</div>

I feel your pain. I just posted about this after hitting the same issue  
at work today. I must have spent a few hours trying to figure out what  
was wrong with our model, because in our case ‘target’ was an  
association itself, which meant that the consequences of using it were  
much stealthier and weirder:

[http://www.rubyfu.com/2007/06/transparent-proxies-part-2.html](http://www.rubyfu.com/2007/06/transparent-proxies-part-2.html)

–Brendan

Josh on Rails wrote:

> I’m working on a cost estimation tool, that allows each estimate created  
> to  
> override base assumptions of price, cost, etc.
> 
> Everything was fine, until we said, “Let’s add a ‘target net revenue’  
> property.”
> 
> So, the resource model got a “target” column. The override model got a  
> “new\_target” column.
> 
> But, whenever I set resource.target, I don’t get a resource at the end;  
> I  
> get target. In other words:
> 
> old\_resource = resource.clone  
> resource.target = new\_target  
> resource == old\_resource # false  
> resource == new\_target # true

---

<div class="post-metadata">

**Author:** ![Josh\_on\_Rails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/df705f/32.png) [@Josh\_on\_Rails](https://www.ruby-forum.com/u/Josh_on_Rails)\
**Post date:** [June 20, 2007, 6:01pm UTC](https://www.ruby-forum.com/t/is-target-a-reserved-word/93989/5 "2007-06-20T18:01:03Z")

</div>

target is not a reserved word. It is however used in ActiveRecord for  
their  
associations. That might be where you are running into problems.

/Shawn
