A table named references

Hi all,

I accidentally generated a scaffold called reference, not realizing
references was apparently a reserved word in MySQL. I thought I could
get away with it, since the scaffold itself seemed to be working, but
now I'm getting an error that suggests Rails doesn't like this
scaffold name.

I'd like to rename it to ref. Is it as simple as a search-replace, or
will I encounter other problems? What's the easiest solution?

Here's the code, in case anyone's interested (in a show view)
  <% @genes_phenotypes_references.each do |phenotype_reference| %>
    <tr>
      <td><%= link_to phenotype_reference.phenotype.long_desc,
phenotype_reference.phenotype %></td>
      <td>?</td>
      <td><%= link_to phenotype_reference.reference %></td>
    </tr>
  <% end %>
genes_phenotypes_references refers to a join table (also a model). The
current view is for gene, so I'm trying to have it print a list of
links to associated phenotypes and the journal article that associates
the gene and the phenotype. Printing the phenotype link works just
fine, but when I try to print the phenotype_reference.reference, it
gives me a link to the current gene show view, (e.g., genes/1),
instead of the reference show view (e.g., references/2).

Many thanks.

Cheers,

John Woods

The University of Texas at Austin
Marcotte Lab | Center for Systems and Synthetic Biology

It should be as simple as changing all uses of the text 'reference' to
'ref' and 'Reference' to 'Ref' plus renaming the files and folders.
That is assuming you have not used the text 'reference' anywhere else
of course. I would advise committing to your source control system
first and then if it is a disaster for some unforeseen reason you can
just revert.

Colin

Thanks so much. I wish there was some kind of protection against
creating scaffolds with reserved words. It's frustrating.

Anyway, thank you for the help!

Can anyone point us at a list of reserved words in RoR that we should
not use for models etc? I have fallen over this myself a couple of
times and it can be difficult to identify that the problem is a name
clash as the errors can be particularly opaque.

Colin

http://wiki.rubyonrails.org/rails/pages/ReservedWords

Great, thanks Rob, it does have a couple of words that I had trouble
with, in the 'Other names reported to have caused trouble' but I
notice that 'reference' is not in there. John are you sure that this
was your problem. I suppose the proof is in whether renaming fixed
it.

Colin

I think the problem is that it's a MySQL reserved word rather than
Rails. Perhaps if different DB software was used it wouldn't be a
problem? I'm not experienced enough to say one way or another.

John Woods wrote:

I think the problem is that it's a MySQL reserved word rather than
Rails.

I thought the Rails DB adapters quoted identifiers precisely so name
clashes of this sort wouldn't occur on the DB side.

Perhaps if different DB software was used it wouldn't be a
problem? I'm not experienced enough to say one way or another.

I doubt that the issue is on the DB side, but if is, I don't think
switching will do it. I think "references" as a keyword is in the SQL
standard, so it's probably reserved in every SQL DBMS that supports
foreign keys.

Best,

I ran into this exact problem with a php app a little while ago and
you get some very odd errors that are not very useful (from what I
recall they were something like, "problems with your sql at 'select *
from references' " which had me looking at the right area, but for the
wrong thing.)

Carl

This should not happen in rails however as it should be something like
select * from `references`

Colin