Forum: Ruby on Rails belongs_to and table name quotes - DO NOT DO THIS

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5565e460a42fbe5669b458b2753f8d34?d=identicon&s=25 codeslush (Guest)
on 2005-11-12 12:49
(Received via mailing list)
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
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 christopher.k.hall (Guest)
on 2005-11-12 12:49
(Received via mailing list)
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
Accad816054fc1b2fa7dae2a2fce5266?d=identicon&s=25 cuong.tran (Guest)
on 2005-11-12 12:49
(Received via mailing list)
Try belongs_to :quote, also take a look at the log file
(log/development.log) to see what sql was generated.
5565e460a42fbe5669b458b2753f8d34?d=identicon&s=25 codeslush (Guest)
on 2005-11-12 12:49
(Received via mailing list)
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 Tran <cuong.tran@gmail.com> wrote:
Try belongs_to :quote, also take a look at the log file
(log/development.log) to see what sql was generated.
This topic is locked and can not be replied to.