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
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
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.
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
t = Thing.find(first)
d = Doohickey.find(first)
t.doohickeys.delete(d)
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs