cinderedmonkey
2008-Aug-25 22:14 UTC
Manipulate retrieved database find query object, multiple tables and one legacy database (phew)
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)
<components type="array">
<component>
<componentid type="integer">1</componentid>
...
<name>Blah</name>
</component>
<component>
...
</component>
</components>
And want to add an item
<version>some version string</version>
which is data from a ''version'' table into that above result
so the result would look sorta like
<components type="array">
<component>
<componentid type="integer">1</componentid>
...
<name>Blah</name>
<version>1.2.3.4</version>
</component>
<component>
...
</component>
</components>
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?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
cinderedmonkey
2008-Aug-25 23:06 UTC
Re: Manipulate retrieved database find query object, multiple tables and one legacy database (phew)
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?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Aug-26 08:27 UTC
Re: Manipulate retrieved database find query object, multiple tables and one legacy database (phew)
On Aug 26, 12:06 am, cinderedmonkey <hubert.yoshiz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 >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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
cinderedmonkey
2008-Aug-26 18:57 UTC
Re: Manipulate retrieved database find query object, multiple tables and one legacy database (phew)
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---