# Belongs\_to and table name quotes - DO NOT DO THIS

**URL:** <https://www.ruby-forum.com/t/belongs-to-and-table-name-quotes-do-not-do-this/47585>\
**Category:** Rails\
**Created:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/belongs-to-and-table-name-quotes-do-not-do-this/47585 "2005-11-12T12:49:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![codeslush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c57346/32.png) [@codeslush](https://www.ruby-forum.com/u/codeslush)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/belongs-to-and-table-name-quotes-do-not-do-this/47585/1 "2005-11-12T12:49:32Z")

</div>

Hello,

I’m a ROR newbie and have been pulling my hair out for a day trying to  
figure out why I was getting an ActiveRecord::StatementInvalid when  
trying to create a new record with a simple relationship. I have been  
playing with ROR for a few days now and, ironically, this was the first  
table that I tried to create associated records against.

Details: Table name: Quotes defined with has\_many Activities. Upon  
trying to create an activity (belongs\_to :quotes) I would get an error  
message indicating the SQL was invalid. This is a very simple  
relationship and I couldn’t understand why I had downloaded samples with  
belongs\_to that worked but why I couldn’t get mine to work.

I found a post (gmane.comp.lang.ruby.rails:21139) with the same exact  
problem but that went unresolved. I’m new to mailing lists and don’t  
know how to reply directly to that post. He had this problem with the  
same table name that I was using. That prompted me to change my table  
name. Upon changing, everything works as expected.

Is there a way that this can get fixed? Anyone building a CRM  
application will need a table called Quotes.

On a side note: I love this application - despite the troubles I had  
with this table. I learned a lot while trying to troubleshoot this  
problem.

Many thanks,

Michael

---

<div class="post-metadata">

**Author:** ![codeslush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c57346/32.png) [@codeslush](https://www.ruby-forum.com/u/codeslush)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/belongs-to-and-table-name-quotes-do-not-do-this/47585/2 "2005-11-12T12:49:32Z")

</div>

perhaps try using singular instead of plural

# an activity belongs to a quote

class Activity \< ActiveRecord::Base  
belongs\_to :quote  
end

# a quote has many activities

class Quote \< ActiveRecord::Base  
has\_many :activities  
end

Chris

---

<div class="post-metadata">

**Author:** ![codeslush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c57346/32.png) [@codeslush](https://www.ruby-forum.com/u/codeslush)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/belongs-to-and-table-name-quotes-do-not-do-this/47585/3 "2005-11-12T12:49:32Z")

</div>

Try belongs\_to :quote, also take a look at the log file  
(log/development.log) to see what sql was generated.

---

<div class="post-metadata">

**Author:** ![codeslush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c57346/32.png) [@codeslush](https://www.ruby-forum.com/u/codeslush)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/belongs-to-and-table-name-quotes-do-not-do-this/47585/4 "2005-11-12T12:49:32Z")

</div>

That was a typo on my part - it was belongs\_to :quote

The problem is with the table name - Changing the table name solves the  
issue all together.

Regards,

Michael

Cuong T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
Try belongs\_to :quote, also take a look at the log file  
(log/development.log) to see what sql was generated.
