mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 13:33:20 +12:00
test: adjust tests for removal of name/type (and defaults)
This commit is contained in:
parent
d5fc20f07c
commit
1cc143e7fa
10 changed files with 48 additions and 25 deletions
|
@ -37,6 +37,7 @@ defmodule Ash.Resource.Relationships.ManyToMany do
|
||||||
],
|
],
|
||||||
destination_field_on_join_table: [
|
destination_field_on_join_table: [
|
||||||
type: :atom,
|
type: :atom,
|
||||||
|
required: true,
|
||||||
doc:
|
doc:
|
||||||
"The field on the join table that should line up with `destination_field` on the related resource. Default: [relationshihp_name]_id"
|
"The field on the join table that should line up with `destination_field` on the related resource. Default: [relationshihp_name]_id"
|
||||||
],
|
],
|
||||||
|
@ -90,8 +91,7 @@ defmodule Ash.Resource.Relationships.ManyToMany do
|
||||||
source_field: opts[:source_field],
|
source_field: opts[:source_field],
|
||||||
destination_field: opts[:destination_field],
|
destination_field: opts[:destination_field],
|
||||||
source_field_on_join_table: opts[:source_field_on_join_table],
|
source_field_on_join_table: opts[:source_field_on_join_table],
|
||||||
destination_field_on_join_table:
|
destination_field_on_join_table: opts[:destination_field_on_join_table]
|
||||||
opts[:destination_field_on_join_table] || :"#{name}_id"
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
{:error, errors} ->
|
{:error, errors} ->
|
||||||
|
|
|
@ -40,9 +40,11 @@ defmodule Ash.Test.Actions.CreateTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
relationships do
|
relationships do
|
||||||
has_one :profile, Profile
|
has_one :profile, Profile, destination_field: :author_id
|
||||||
|
|
||||||
has_many :posts, Ash.Test.Actions.CreateTest.Post, reverse_relationship: :author
|
has_many :posts, Ash.Test.Actions.CreateTest.Post,
|
||||||
|
reverse_relationship: :author,
|
||||||
|
destination_field: :author
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -42,9 +42,9 @@ defmodule Ash.Test.Actions.DestroyTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
relationships do
|
relationships do
|
||||||
has_one :profile, Profile
|
has_one :profile, Profile, destination_field: :author_id
|
||||||
|
|
||||||
has_many :posts, Ash.Test.Actions.CreateTest.Post
|
has_many :posts, Ash.Test.Actions.CreateTest.Post, destination_field: :author_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ defmodule Ash.Test.Actions.ReadTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
relationships do
|
relationships do
|
||||||
has_many :posts, Ash.Test.Actions.ReadTest.Post
|
has_many :posts, Ash.Test.Actions.ReadTest.Post, destination_field: :author
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,9 @@ defmodule Ash.Test.Actions.SideLoadTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
relationships do
|
relationships do
|
||||||
has_many :posts, Ash.Test.Actions.SideLoadTest.Post, reverse_relationship: :author
|
has_many :posts, Ash.Test.Actions.SideLoadTest.Post,
|
||||||
|
reverse_relationship: :author,
|
||||||
|
destination_field: :author_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -40,9 +40,11 @@ defmodule Ash.Test.Actions.UpdateTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
relationships do
|
relationships do
|
||||||
has_one :profile, Profile
|
has_one :profile, Profile, destination_field: :author_id
|
||||||
|
|
||||||
has_many :posts, Ash.Test.Actions.UpdateTest.Post, reverse_relationship: :author
|
has_many :posts, Ash.Test.Actions.UpdateTest.Post,
|
||||||
|
reverse_relationship: :author,
|
||||||
|
destination_field: :author_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ defmodule Ash.Test.Filter.FilterTest do
|
||||||
reverse_relationship: :author2,
|
reverse_relationship: :author2,
|
||||||
destination_field: :author1_id
|
destination_field: :author1_id
|
||||||
|
|
||||||
has_one :profile, Profile
|
has_one :profile, Profile, destination_field: :user_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ defmodule Ash.Test.Resource.Relationshihps.HasManyTest do
|
||||||
test "it creates a relationship" do
|
test "it creates a relationship" do
|
||||||
defposts do
|
defposts do
|
||||||
relationships do
|
relationships do
|
||||||
has_many :foobar, FooBar
|
has_many :foobar, FooBar, destination_field: :post_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ defmodule Ash.Test.Resource.Relationshihps.HasManyTest do
|
||||||
fn ->
|
fn ->
|
||||||
defposts do
|
defposts do
|
||||||
relationships do
|
relationships do
|
||||||
has_many :foobar, FooBar, source_field: "foo"
|
has_many :foobar, FooBar, source_field: "foo", destination_field: :post_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,7 +21,7 @@ defmodule Ash.Test.Resource.Relationshihps.HasOneTest do
|
||||||
test "it creates a relationship" do
|
test "it creates a relationship" do
|
||||||
defposts do
|
defposts do
|
||||||
relationships do
|
relationships do
|
||||||
has_one :foobar, FooBar
|
has_one :foobar, FooBar, destination_field: :post_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ defmodule Ash.Test.Resource.Relationshihps.HasOneTest do
|
||||||
fn ->
|
fn ->
|
||||||
defposts do
|
defposts do
|
||||||
relationships do
|
relationships do
|
||||||
has_one :foobar, FooBar, source_field: "foo"
|
has_one :foobar, FooBar, source_field: "foo", destination_field: :post_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,7 +21,10 @@ defmodule Ash.Test.Resource.Relationships.ManyToManyTest do
|
||||||
test "it creates a relationship and a join relationship" do
|
test "it creates a relationship and a join relationship" do
|
||||||
defposts do
|
defposts do
|
||||||
relationships do
|
relationships do
|
||||||
many_to_many :related_posts, Post, through: SomeResource
|
many_to_many :related_posts, Post,
|
||||||
|
through: SomeResource,
|
||||||
|
source_field_on_join_table: :post_id,
|
||||||
|
destination_field_on_join_table: :related_post_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -29,7 +32,7 @@ defmodule Ash.Test.Resource.Relationships.ManyToManyTest do
|
||||||
%Ash.Resource.Relationships.HasMany{
|
%Ash.Resource.Relationships.HasMany{
|
||||||
cardinality: :many,
|
cardinality: :many,
|
||||||
destination: SomeResource,
|
destination: SomeResource,
|
||||||
destination_field: :posts_id,
|
destination_field: :post_id,
|
||||||
name: :related_posts_join_assoc,
|
name: :related_posts_join_assoc,
|
||||||
source: Ash.Test.Resource.Relationships.ManyToManyTest.Post,
|
source: Ash.Test.Resource.Relationships.ManyToManyTest.Post,
|
||||||
source_field: :id,
|
source_field: :id,
|
||||||
|
@ -40,11 +43,11 @@ defmodule Ash.Test.Resource.Relationships.ManyToManyTest do
|
||||||
cardinality: :many,
|
cardinality: :many,
|
||||||
destination: Ash.Test.Resource.Relationships.ManyToManyTest.Post,
|
destination: Ash.Test.Resource.Relationships.ManyToManyTest.Post,
|
||||||
destination_field: :id,
|
destination_field: :id,
|
||||||
destination_field_on_join_table: :related_posts_id,
|
destination_field_on_join_table: :related_post_id,
|
||||||
name: :related_posts,
|
name: :related_posts,
|
||||||
source: Ash.Test.Resource.Relationships.ManyToManyTest.Post,
|
source: Ash.Test.Resource.Relationships.ManyToManyTest.Post,
|
||||||
source_field: :id,
|
source_field: :id,
|
||||||
source_field_on_join_table: :posts_id,
|
source_field_on_join_table: :post_id,
|
||||||
through: SomeResource,
|
through: SomeResource,
|
||||||
type: :many_to_many,
|
type: :many_to_many,
|
||||||
reverse_relationship: nil
|
reverse_relationship: nil
|
||||||
|
@ -61,7 +64,10 @@ defmodule Ash.Test.Resource.Relationships.ManyToManyTest do
|
||||||
fn ->
|
fn ->
|
||||||
defposts do
|
defposts do
|
||||||
relationships do
|
relationships do
|
||||||
many_to_many :foobars, Foobar, through: "some_table"
|
many_to_many :foobars, Foobar,
|
||||||
|
through: "some_table",
|
||||||
|
source_field_on_join_table: :source_post_id,
|
||||||
|
destination_field_on_join_table: :destination_post_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -71,7 +77,10 @@ defmodule Ash.Test.Resource.Relationships.ManyToManyTest do
|
||||||
test "you can pass a module to `through`" do
|
test "you can pass a module to `through`" do
|
||||||
defposts do
|
defposts do
|
||||||
relationships do
|
relationships do
|
||||||
many_to_many :foobars, Foobar, through: FooBars
|
many_to_many :foobars, Foobar,
|
||||||
|
through: FooBars,
|
||||||
|
source_field_on_join_table: :source_post_id,
|
||||||
|
destination_field_on_join_table: :destination_post_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -83,7 +92,10 @@ defmodule Ash.Test.Resource.Relationships.ManyToManyTest do
|
||||||
fn ->
|
fn ->
|
||||||
defposts do
|
defposts do
|
||||||
relationships do
|
relationships do
|
||||||
many_to_many :foobars, Foobar, through: FooBars, source_field_on_join_table: "what"
|
many_to_many :foobars, Foobar,
|
||||||
|
through: FooBars,
|
||||||
|
source_field_on_join_table: "what",
|
||||||
|
destination_field_on_join_table: :destination_post_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -99,7 +111,8 @@ defmodule Ash.Test.Resource.Relationships.ManyToManyTest do
|
||||||
relationships do
|
relationships do
|
||||||
many_to_many :foobars, Foobar,
|
many_to_many :foobars, Foobar,
|
||||||
through: FooBar,
|
through: FooBar,
|
||||||
destination_field_on_join_table: "what"
|
destination_field_on_join_table: "what",
|
||||||
|
source_field_on_join_table: :source_post_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -115,7 +128,9 @@ defmodule Ash.Test.Resource.Relationships.ManyToManyTest do
|
||||||
relationships do
|
relationships do
|
||||||
many_to_many :foobars, Foobar,
|
many_to_many :foobars, Foobar,
|
||||||
through: FooBar,
|
through: FooBar,
|
||||||
source_field: "what"
|
source_field: "what",
|
||||||
|
source_field_on_join_table: :source_post_id,
|
||||||
|
destination_field_on_join_table: :destination_post_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -131,7 +146,9 @@ defmodule Ash.Test.Resource.Relationships.ManyToManyTest do
|
||||||
relationships do
|
relationships do
|
||||||
many_to_many :foobars, Foobar,
|
many_to_many :foobars, Foobar,
|
||||||
through: FooBars,
|
through: FooBars,
|
||||||
destination_field: "what"
|
destination_field: "what",
|
||||||
|
source_field_on_join_table: :source_post_id,
|
||||||
|
destination_field_on_join_table: :destination_post_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue