Załóżmy, że User
ma wiele Document
s i jedną Document
, nad którą aktualnie pracują. Jak mam to reprezentować w szynach?Szyny: has_many, ale także has_one pod inną nazwą
Chcę powiedzieć current_user.current_document = Document.first
(z lub bez current_ przed dokumentem) i nie zmieniaj kolekcji current_user.documents
.
To jest to, co mam:
class Document < ActiveRecord::Base
belongs_to :user
end
class User < ActiveRecord::Base
has_many :documents
has_one :document
end
problemem jest to, że kiedy mówię current_user.document = some_document
, usuwa dokument uprzednio zapisanego w current_user.document
z current_user.documents
. Ma to sens ze względu na relację has_one
, którą ma , ale nie jest to, czego chcę. Jak mogę to naprawić?
Dzięki! I dla jasności dla innych, nazwa kolumny w tym przypadku będzie "current_document_id" w tabeli 'users'. – Peter