# MySql Errors On .save

**URL:** <https://www.ruby-forum.com/t/mysql-errors-on-save/118944>\
**Category:** Rails\
**Created:** [November 1, 2007, 5:02pm UTC](https://www.ruby-forum.com/t/mysql-errors-on-save/118944 "2007-11-01T17:02:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![twaters](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@twaters](https://www.ruby-forum.com/u/twaters)\
**Post date:** [November 1, 2007, 5:02pm UTC](https://www.ruby-forum.com/t/mysql-errors-on-save/118944/1 "2007-11-01T17:02:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![twaters](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@twaters](https://www.ruby-forum.com/u/twaters)\
**Post date:** [November 1, 2007, 5:28pm UTC](https://www.ruby-forum.com/t/mysql-errors-on-save/118944/2 "2007-11-01T17:28:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![twaters](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@twaters](https://www.ruby-forum.com/u/twaters)\
**Post date:** [November 1, 2007, 6:24pm UTC](https://www.ruby-forum.com/t/mysql-errors-on-save/118944/3 "2007-11-01T18:24:46Z")

</div>

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:

1. Reproducing it with the console
2. The card object
3. The cardfront object
4. The cardback object
5. The (3) tables involved.

Imagine modeling a playing card. A card “has a” cardfront and a  
cardback.

Any help very much appreciated.

Tim

1. 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

1. The card object  
class Card \< ActiveRecord::Base  
has\_one :cardfront  
has\_one :cardback  
end

2. The cardfront object  
class Cardfront \< ActiveRecord::Base  
belongs\_to :card  
end

3. 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`)  
)

---

<div class="post-metadata">

**Author:** ![twaters](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@twaters](https://www.ruby-forum.com/u/twaters)\
**Post date:** [November 1, 2007, 8:28pm UTC](https://www.ruby-forum.com/t/mysql-errors-on-save/118944/4 "2007-11-01T20:28:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![twaters](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@twaters](https://www.ruby-forum.com/u/twaters)\
**Post date:** [November 1, 2007, 8:32pm UTC](https://www.ruby-forum.com/t/mysql-errors-on-save/118944/5 "2007-11-01T20:32:58Z")

</div>

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
