# Manipulate retrieved database find query object, multiple tables and one legacy database (phew)

**URL:** <https://www.ruby-forum.com/t/manipulate-retrieved-database-find-query-object-multiple-tables-and-one-legacy-database-phew/146830>\
**Category:** Rails\
**Created:** [August 26, 2008, 12:38am UTC](https://www.ruby-forum.com/t/manipulate-retrieved-database-find-query-object-multiple-tables-and-one-legacy-database-phew/146830 "2008-08-26T00:38:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cinderedmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/74df32/32.png) [@cinderedmonkey](https://www.ruby-forum.com/u/cinderedmonkey)\
**Post date:** [August 26, 2008, 12:38am UTC](https://www.ruby-forum.com/t/manipulate-retrieved-database-find-query-object-multiple-tables-and-one-legacy-database-phew/146830/1 "2008-08-26T00:38:21Z")

</div>

Hi,  
First, I am forced to use a legacy database.  
My problem is that I need data from two separate tables which I can  
get easily enough separately.  
What I do need to know is how to join that information together so I  
can send the result as one xml result.

I.e. from one query I get (after render to xml)  
  
  
1  
…  
Blah  
  
  
…

And want to add an item  
some version string  
which is data from a ‘version’ table into that above result

so the result would look sorta like  
  
  
1  
…  
Blah  
1.2.3.4  
  
  
…

Now I can’t really use association since it’s a legacy database and  
the ‘id’ in the ‘component’ table in MySQL does not correspond to a  
‘version\_id’ column in the ‘version’ table as there is no  
‘version\_id’.

Is my only choice using XML Builder? Or can I manipulate the object  
retrieved from the database find queries and send it straight to  
render xml?

Or am I missing something really simple?

---

<div class="post-metadata">

**Author:** ![cinderedmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/74df32/32.png) [@cinderedmonkey](https://www.ruby-forum.com/u/cinderedmonkey)\
**Post date:** [August 26, 2008, 1:07am UTC](https://www.ruby-forum.com/t/manipulate-retrieved-database-find-query-object-multiple-tables-and-one-legacy-database-phew/146830/2 "2008-08-26T01:07:36Z")

</div>

Just more info…  
I’m trying this query  
find\_by\_sql(“SELECT components.logicalname, versions.level,  
versions.branch, versions.sequence from components, versions WHERE  
components.componentid = '” + componentid + “’” + " AND  
versions.componentid = ‘" + componentid + "’")

Ugly but seems to work from mysql but from the console (netbeans) it  
only outputs components.logicalname and nothing from versions.level,  
versions.branch and versions.sequence

Why would the output be different?  
Any ideas?

---

<div class="post-metadata">

**Author:** ![cinderedmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/74df32/32.png) [@cinderedmonkey](https://www.ruby-forum.com/u/cinderedmonkey)\
**Post date:** [August 26, 2008, 10:28am UTC](https://www.ruby-forum.com/t/manipulate-retrieved-database-find-query-object-multiple-tables-and-one-legacy-database-phew/146830/3 "2008-08-26T10:28:14Z")

</div>

On Aug 26, 12:06 am, cinderedmonkey [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> 

because what you see in the console (ie what the inspect method  
returns) is hardwired just to show attributes from that table. The  
other ones (branch etc…) are there (try calling them) they’re just  
not displayed. You could also try using to\_xml’s :methods option. I  
wouldn’t say builder is a big deal, I’d far rather some nice clean  
builder than a bunch of contorted stuff to squeeze the right thing out  
of to\_xml

Fred

---

<div class="post-metadata">

**Author:** ![cinderedmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/74df32/32.png) [@cinderedmonkey](https://www.ruby-forum.com/u/cinderedmonkey)\
**Post date:** [August 26, 2008, 9:00pm UTC](https://www.ruby-forum.com/t/manipulate-retrieved-database-find-query-object-multiple-tables-and-one-legacy-database-phew/146830/4 "2008-08-26T21:00:23Z")

</div>

Thanks, it seems it was a display problem.  
It’s working now.  
I’ll see about making it cleaner with builder next.  
Again, thanks, greatly appreciated.

Hubert
