# This topic needs a title

**URL:** <https://discuss.rubyonrails.org/t/this-topic-needs-a-title/1559>\
**Category:** rubyonrails-talk\
**Created:** [September 13, 2006, 1:46pm UTC](https://discuss.rubyonrails.org/t/this-topic-needs-a-title/1559 "2006-09-13T13:46:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Berger\_Daniel](https://avatars.discourse-cdn.com/v4/letter/b/0ea827/32.png) [@Berger\_Daniel](https://discuss.rubyonrails.org/u/Berger_Daniel)\
**Post date:** [September 13, 2006, 1:46pm UTC](https://discuss.rubyonrails.org/t/this-topic-needs-a-title/1559/1 "2006-09-13T13:46:15Z")

</div>

Hi all,

Windows XP Oracle 10g client OCI8 0.1.16 Ruby 1.8.5 Rails 1.1.6

I'm hitting weird behavior with the Oracle adapter and a find\_by\_sql call on a multi-table join.

The SQL looks like this:

SELECT DISTINCT e1.ip\_address, loc.street, loc.city, loc.state FROM schema.net\_element ne, schema.equipment e1, schema.equipment e2, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;schema.building b, schema.cust\_loc cl, schema.location loc WHERE e2.equipment\_id = e1.equipment\_id AND e2.some\_column like 'SOME\_VAL%' AND e1.equipment\_id = ne.net\_element\_id AND ne.class\_name = 'FooBar' AND e1.building\_id = b.building\_id AND b.main\_address = cl.cust\_loc\_id AND cl.location\_id = loc.location\_id

So, I setup a class for the 'Location' table like this:

class OracleLocation \< ActiveRecord::Base &nbsp;&nbsp;&nbsp;establish\_connection( &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:adapter =\> "oracle", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:database =\> "our\_db", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:username =\> "user", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:password =\> "password" &nbsp;&nbsp;&nbsp;) &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;set\_table\_name :location &nbsp;&nbsp;&nbsp;set\_primary\_key "location\_id" end

I can get a record back just fine:

loc = OracleLocation.find\_by\_sql(sql).first p loc

#\<OracleLocation:0x385c610 @attributes={"state"=\>"WA", "street"=\>"1234 Block St", "city"=\>"Smallville", "ip\_address"=\>"172.1.2.3"}\>

However, if I try to refer to an attribute, either directly or via the 'attributes' method, I get an error:

p loc.attributes # Boom!

(eval):3:in ` __send__': ORA-04043: object location does not exist (OCIError) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (eval):3:in `describe' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active\_record/connection\_adapters/oracle\_adapter.rb:

361:in `columns' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:696:in `columns' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active\_record/base.rb:704:in `columns_hash' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1562:in `column\_for\_attribute'

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active\_record/base.rb:1801:in `read_attribute' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:2067:in `send' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active\_record/base.rb:2067:in `clone\_attribute\_value

' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active\_record/base.rb:2061:in `clone_attributes' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/inflector.rb:161:in `inject' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active\_record/base.rb:2060:in `each' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:2060:in `inject' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active\_record/base.rb:2060:in `clone_attributes' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1519:in `attributes' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from oracletest2.rb:35:in `send' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from oracletest2.rb:35

This error confuses me. There clearly \*is\* a location table, or the query wouldn't work in the first place. Also, the fact that I'm getting back an ORA-04043 indicates to me that, when I call loc.attributes, it's calling out to the database \*again\* for some reason. Why?

Is this error caused by the fact that I'm doing a multi-table join here, but haven't actually mapped any of the other tables besides Location? What's going on?

Thanks,

Dan

This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments.

---

<div class="post-metadata">

**Author:** ![Anthony\_Carlos](https://avatars.discourse-cdn.com/v4/letter/a/e95f7d/32.png) [@Anthony\_Carlos](https://discuss.rubyonrails.org/u/Anthony_Carlos)\
**Post date:** [September 13, 2006, 2:19pm UTC](https://discuss.rubyonrails.org/t/this-topic-needs-a-title/1559/2 "2006-09-13T14:19:44Z")

</div>

Dan:

What's the class of loc?

p loc.class

Let's just be sure it's the right kind of class first.

-Anthony
