I have Lineup and Piece models joined by piece_lineup model (has many through). I added a 'status' column to the piece_lineup model but i can't figure out how to reference that attribute and/or change it. When listing the pieces associated with a lineup, I also want to list the status of the piece as it relates to the lineup. How do I do that?
Asked
Active
Viewed 59 times
1 Answers
0
It's very simple to get this column. Add to your model:
has_many :pieces, through: :piece_lineup, select: "pieces.*, piece_lineup.status as status"
If you have to change this value, you should create Lineup#status_for_piece=(piece, status)
(as example) method. Find necessary row and update status.
Inserting is not elegant way, but join table is not a good place for frequently updated data at all

caulfield
- 1,383
- 1
- 11
- 21