Hi, recordvar.destroy doesn't work.. gives me the following error: Unknown column 'id' in 'where clause' there's gotta be a way to delete entries in a link table.. any help? thanks, Stuart
on 2007-07-11 15:45
on 2007-07-11 18:42
stewbawka wrote: > Hi, > > recordvar.destroy doesn't work.. gives me the following error: > > Unknown column 'id' in 'where clause' > > there's gotta be a way to delete entries in a link table.. any help? > > thanks, > > Stuart Esthetically all tables should have an id even if it acts only as a surrogate to uniquely identify that row from others. Also, my rule of thumb, never use compound primary keys. (Which you are doing if you have a link table with no surrogate). hope this helps.
on 2007-07-11 20:20
you example begs the question how are you instantiating a record from a join table without an id in the first place? typically these tables will not have an id column and therefore no model to go along with it. this is what you would see in a habtm relationship. the table is in a sense invisible and it's only purpose is tho join (or link, in your words) two other tables. of course, a has_many through join is different, as the join table does have a representative model. left table <-- join table --> right table what you are attempting to do in this case is destroy the relationship between 2 tables, which is easy enough, but you have to do it through one of the two models representing either the left or right tables. ie thing habtm doohickeys doohickey habtm things # say t and d have a relationship in the join table t = Thing.find(first) d = Doohickey.find(first) t.doohickeys.delete(d) # or # d.things.delete(t) # will work as well