-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
assign_related
option to RelatedSet
; auto-assign back-relatio…
…ns for one-to-one
- Loading branch information
Showing
8 changed files
with
73 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,13 +101,31 @@ describe Marten::DB::Query::RelatedSet do | |
end | ||
|
||
describe "#fetch" do | ||
it "sets the related object automatically" do | ||
it "assigns the related object if assign_related is explicitly set to true" do | ||
user = TestUser.create!(username: "jd1", email: "[email protected]", first_name: "John", last_name: "Doe") | ||
Post.create!(author: user, title: "Post 1") | ||
|
||
qset = Marten::DB::Query::RelatedSet(Post).new(user, "author_id") | ||
qset = Marten::DB::Query::RelatedSet(Post).new(user, "author_id", assign_related: true) | ||
|
||
qset[0].get_related_object_variable(:author).should eq user | ||
end | ||
|
||
it "does not assign the related object when assign_related is explicitly set to false" do | ||
user = TestUser.create!(username: "jd1", email: "[email protected]", first_name: "John", last_name: "Doe") | ||
Post.create!(author: user, title: "Post 1") | ||
|
||
qset = Marten::DB::Query::RelatedSet(Post).new(user, "author_id", assign_related: false) | ||
|
||
qset[0].get_related_object_variable(:author).should be_nil | ||
end | ||
|
||
it "does not assign the related object when assign_related is left as the default value (false)" do | ||
user = TestUser.create!(username: "jd1", email: "[email protected]", first_name: "John", last_name: "Doe") | ||
Post.create!(author: user, title: "Post 1") | ||
|
||
qset = Marten::DB::Query::RelatedSet(Post).new(user, "author_id") | ||
|
||
qset[0].get_related_object_variable(:author).should be_nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters