Hi All,
I am a real neophyte with Rails and am struggling with something. I hope
you can point me in the right direction.
I have a model of an object that
class Thing< ActiveRecord::Base
attr_accessor :locator_id
has_one :otherthing
has_one :differentthing
end
I can create and delete these things until the cows come home. However,
trying to change the data and save/update I get a rendered SQL error in
the form:
ActionView::TemplateError (Mysql::Error: You have an error in your SQL
syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near ‘WHERE id
= 40’ at line 1: UPDATE
things SET WHERE id
= 40)…etc.
So, I reduce this to it’s elements…a find followed immediately
followed by a save and I get this error.
So, it looks to me like a mismatch in the SQL that is generated and the
version of MySql is Server version: 5.0.41 MySQL Community Server (GPL)
and
Rails 1.2.3.
Any help very much appreciated.
Sincerely,
Tim
On 1 Nov 2007, at 16:02, Tim W. wrote:
attr_accessor :locator_id
ActionView::TemplateError (Mysql::Error: You have an error in your SQL
syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near ‘WHERE id
= 40’ at line 1: UPDATE
things SET WHERE id
= 40)…etc.
So, I reduce this to it’s elements…a find followed immediately
followed by a save and I get this error.
That sql just looks wrong. What columns exist on the table. Are you
passing any extra options into find ?
Fred
Frederick C. wrote:
On 1 Nov 2007, at 16:02, Tim W. wrote:
attr_accessor :locator_id
ActionView::TemplateError (Mysql::Error: You have an error in your SQL
syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near ‘WHERE id
= 40’ at line 1: UPDATE
things SET WHERE id
= 40)…etc.
So, I reduce this to it’s elements…a find followed immediately
followed by a save and I get this error.
That sql just looks wrong. What columns exist on the table. Are you
passing any extra options into find ?
Fred
Hi Fred,
Thank you for taking a look. I agree the SQL just looks wroung. The SET
in particular is wierd.
Below my sig I have:
- Reproducing it with the console
- The card object
- The cardfront object
- The cardback object
- The (3) tables involved.
Imagine modeling a playing card. A card “has a” cardfront and a
cardback.
Any help very much appreciated.
Tim
- Reproducing it with the console
Loading development environment.
@card = Card.find(:first, :conditions => 40)
=> #<Card:0x3563904 @attributes={“id”=>“40”}>
@card.save
ActiveRecord::StatementInvalid: Mysql::Error: You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near ‘WHERE id
= 40’ at line 1:
UPDATE cards SET WHERE id
= 40
-
The card object
class Card < ActiveRecord::Base
has_one :cardfront
has_one :cardback
end
-
The cardfront object
class Cardfront < ActiveRecord::Base
belongs_to :card
end
-
The cardback object
class Cardback < ActiveRecord::Base
belongs_to :card
end
The tables look like:
CREATE TABLE cards
(
id
int(11) NOT NULL auto_increment,
PRIMARY KEY (id
)
)
CREATE TABLE cardfronts
(
id
int(11) NOT NULL auto_increment,
theme
text,
priority
int(11) default NULL,
estimate
int(11) default NULL,
notes
text,
card_id
int(11) default NULL,
PRIMARY KEY (id
)
)
CREATE TABLE cardbacks
(
id
int(11) NOT NULL auto_increment,
card_id
int(11) default NULL,
PRIMARY KEY (id
)
)
On 1 Nov 2007, at 17:24, Tim W. wrote:
things SET WHERE id
= 40)…etc.
Thank you for taking a look. I agree the SQL just looks wroung. The
SET
in particular is wierd.
I’ve looked at the source and this is just a bug in rails. It’s just
not expecting a table with no attributes other than the primary key.
Fred
Frederick C. wrote:
On 1 Nov 2007, at 17:24, Tim W. wrote:
things SET WHERE id
= 40)…etc.
Thank you for taking a look. I agree the SQL just looks wroung. The
SET
in particular is wierd.
I’ve looked at the source and this is just a bug in rails. It’s just
not expecting a table with no attributes other than the primary key.
Fred
I am indebted. I was wondering about that, but the add’s and delete’s
worked fine and being new to Rails (and to ORM in general) thought I was
being really stupid. Makes sense now that you’ve sussed it out, the SET
would have a collection of attributes, which just ainna there, I’m
assuming.
Thank you Frederik, hope I can return the favor someday.
Sincerely,
Tim