# Updating Table without ID Column

**URL:** <https://www.ruby-forum.com/t/updating-table-without-id-column/55117>\
**Category:** Rails\
**Created:** [March 17, 2006, 2:40am UTC](https://www.ruby-forum.com/t/updating-table-without-id-column/55117 "2006-03-17T02:40:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sideshow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@sideshow](https://www.ruby-forum.com/u/sideshow)\
**Post date:** [March 17, 2006, 2:40am UTC](https://www.ruby-forum.com/t/updating-table-without-id-column/55117/1 "2006-03-17T02:40:19Z")

</div>

Hey All,

I’ve been having a slight problem updating attributes for a row that  
matches something other than it’s ID…For ex:

My table that has 3 rows…ColumnID, ColumnTitle, and ColumnDescription.  
I want to update a row in that table WHERE CoumnTitle = @myvar…But  
whenever i run update\_attrbutes[:mytable] it’s looking for an id for the  
record when i need to to look for the title…is there a way to override  
that?

Any help is much appreciated!

---

<div class="post-metadata">

**Author:** ![sideshow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@sideshow](https://www.ruby-forum.com/u/sideshow)\
**Post date:** [March 17, 2006, 2:50am UTC](https://www.ruby-forum.com/t/updating-table-without-id-column/55117/2 "2006-03-17T02:50:05Z")

</div>

Hey Adam. Would you send the code of your method along? That will make  
it easier to help.

THanks  
Clint

---

<div class="post-metadata">

**Author:** ![sideshow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@sideshow](https://www.ruby-forum.com/u/sideshow)\
**Post date:** [March 17, 2006, 3:21am UTC](https://www.ruby-forum.com/t/updating-table-without-id-column/55117/3 "2006-03-17T03:21:47Z")

</div>

Clint P. wrote:

> Hey Adam. Would you send the code of your method along? That will make  
> it easier to help.
> 
> THanks  
> Clint

Sure…Something like this:

The view is just a form with the 3 rows (ColumnID, ColumnTitle, and  
ColumnDescription), I specify the value for ColumnID in a hidden field  
(i get the value from the URL).

Controller is a basic update method:

#controller  
def save\_form  
@column = Columns.find\_by\_ColumnID(params[:id])  
if @column.update\_attributes(params[:column])  
flash[:notice] = ‘Column was successfully updated.’  
redirect\_to :action =\> ‘show’, :id =\> @column  
else  
render :action =\> ‘edit’  
end  
end

When it executes save\_form is notifies me there is no id column in  
UPDATE…WHERE id = NULL, but i want it to update where ColumnID =  
hidden ColumnID value from the form.

It’s pretty basic, if i could only specify the update code it would be  
simple.

Instead of it running UPDATE Table SET ColumnTitle = ColumnTitle WHERE  
id = NULL

It needs to run:

UPDATE Table SET ColumnTitle = ColumnTitle WHERE ColumnID = ColumnID

---

<div class="post-metadata">

**Author:** ![sideshow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@sideshow](https://www.ruby-forum.com/u/sideshow)\
**Post date:** [March 29, 2006, 11:55pm UTC](https://www.ruby-forum.com/t/updating-table-without-id-column/55117/4 "2006-03-29T23:55:27Z")

</div>

Still no luck here. Really got me stumped.

Any hints would really help!
