hyphen on columns name.. help.

11 views
Skip to first unread message

rek2

unread,
Apr 15, 2008, 12:28:10 AM4/15/08
to Ru...@libre.binaryfreedom.info, o...@libre.binaryfreedom.info, Rails@libre.binaryfreedom.info:Talk <rubyonrails-talk@googlegroups.com>,
I have a issue that I can't seen to fix.. I search all over.. and a lot
about how to work with legacy *table* names but nothing about *column*
names...
this will not work because of the hyphen:
@vcards = Vcard.find(:all, :select => "collection-owner")


this below will work but give me a lot of junk..!!
@vcards = Vcard.find(:all, :select => "`collection-owner`")

as well this:
@vcards = Vcard.find(:all, :select => "'collection-owner'")

but when I call this from a:
<%= render :blablabla, :collection => @vcards %>

and in the _blablabla.rhtml
<tr class="<%= cycle('odd', 'even') -%>">
<td><b><%= @vcards -%></td>
</tr>

I will just get ##### and more garbage..
same when I do with console

can anyone tell me how can I work with column names with "-"
hyphens...????? this is frustrating me.. I loved rails but this is
starting to annoy me..
because I understand that tables should be created such a way but there
should be options to work
with legacy tables and not only table names and indexes but also column
names... I have not found anything so far
and trust me I HAVE LOOK and I am not the best using Google but my last
hope before I finish this project on PHP is this call.

HELP!

Brandon Casci

unread,
Apr 15, 2008, 8:36:07 AM4/15/08
to boston-r...@googlegroups.com
I don't think a hyphen is your problem.

From your example, your outputting the collection @vcards. @vcards is an array containing Vcard objects, and rails would just print a # in this case. Try looping through that array in your view.

<% for vcard in @vcards -%>

<tr class="<%= cycle('odd', 'even') -%>">
 <td><b><%= vcard['collection-owner'] %></td>
</tr>
<% end -%>

You could do something like vcard.collection_owner too, but first you'd have to add a little code  so  the legacy column names can be accessed through valid method names.

Zack, Benjamin

unread,
Apr 15, 2008, 10:41:51 AM4/15/08
to boston-r...@googlegroups.com
One thing that has worked for me when working with legacy databases is to create a set of views on all the relevant tables. You can use all the rails conventions on the view and column names so things should work more naturally. This works really well with Oracle and the OCI adapter but I haven't tried it on other systems.
 
-Ben


From: boston-r...@googlegroups.com [mailto:boston-r...@googlegroups.com] On Behalf Of Brandon Casci
Sent: Tuesday, April 15, 2008 8:36 AM
To: boston-r...@googlegroups.com
Subject: Re: hyphen on columns name.. help.

Brandon Casci

unread,
Apr 15, 2008, 10:45:52 AM4/15/08
to boston-r...@googlegroups.com
High five on that one...I forgot about that, but I did this for a sql server database way back. Worked great.
Reply all
Reply to author
Forward
0 new messages