Right now it is possible to use the #create query set method as part of reverse query sets and create records that are actually not associated with the related record from which the query set was created.
For example, let's consider the following models:
class Author < Marten::Model
field :id, :big_int, primary_key: true, auto: true
field :name, :string, max_size: 128
end
class Book < Marten::Model
field :id, :big_int, primary_key: true, auto: true
field :title, :string, max_size: 128
field :author, :many_to_one, to: Author, related: :books
end
Right now it is possible to create Book records through the books reverse query set that are not associated with the Author record from which the query set originated:
Let's ensure that the records that are created from a reverse query sets like that are automatically scoped to the record from which the query set originated.
We should also ensure that overriding the related record explicitly is forbidden. When this happens, a dedicated exception (Marten::DB::Errors::UnmetQuerySetCondition) should be raised:
Description
Right now it is possible to use the
#create
query set method as part of reverse query sets and create records that are actually not associated with the related record from which the query set was created.For example, let's consider the following models:
Right now it is possible to create
Book
records through thebooks
reverse query set that are not associated with theAuthor
record from which the query set originated:Proposition
Let's ensure that the records that are created from a reverse query sets like that are automatically scoped to the record from which the query set originated.
For example:
We should also ensure that overriding the related record explicitly is forbidden. When this happens, a dedicated exception (
Marten::DB::Errors::UnmetQuerySetCondition
) should be raised: