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 --------------------------------- Yahoo! FareChase - Search multiple travel sites in one click. _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
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 On 11/9/05, Michael <codeslush-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> > 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*<http://article.gmane.org/gmane.comp.lang.ruby.rails/21139/match=belongs+to+quote>) > 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 > > ------------------------------ > Yahoo! FareChase - Search multiple travel sites in one click.<http://us.lrd.yahoo.com/_ylc=X3oDMTFqODRtdXQ4BF9TAzMyOTc1MDIEX3MDOTY2ODgxNjkEcG9zAzEEc2VjA21haWwtZm9vdGVyBHNsawNmYw--/SIG=110oav78o/**http%3a//farechase.yahoo.com/> > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Try belongs_to :quote, also take a look at the log file (log/development.log) to see what sql was generated. On 11/9/05, Michael <codeslush-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> 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 > > > > ________________________________ > Yahoo! FareChase - Search multiple travel sites in one click. > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
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-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: Try belongs_to :quote, also take a look at the log file (log/development.log) to see what sql was generated. On 11/9/05, Michael wrote:> 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 > > > > ________________________________ > Yahoo! FareChase - Search multiple travel sites in one click. > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails --------------------------------- Yahoo! FareChase - Search multiple travel sites in one click. _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails