Skip to content

Commit 5a195b1

Browse files
authored
Merge pull request #1119 from code-corps/fix-identifiers-in-views
Fix identifiers in views to not preload for belongs_to IDs
2 parents d8433af + 4f23fc9 commit 5a195b1

29 files changed

+63
-76
lines changed
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
defmodule CodeCorpsWeb.CommentView do
22
@moduledoc false
3-
use CodeCorpsWeb.PreloadHelpers, default_preloads: [:user, :task]
43
use CodeCorpsWeb, :view
54
use JaSerializer.PhoenixView
65

@@ -9,6 +8,6 @@ defmodule CodeCorpsWeb.CommentView do
98
:modified_from, :updated_at
109
]
1110

12-
has_one :user, serializer: CodeCorpsWeb.UserView
13-
has_one :task, serializer: CodeCorpsWeb.TaskView
11+
has_one :task, type: "task", field: :task_id
12+
has_one :user, type: "user", field: :user_id
1413
end

lib/code_corps_web/views/donation_goal_view.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
defmodule CodeCorpsWeb.DonationGoalView do
22
@moduledoc false
3-
use CodeCorpsWeb.PreloadHelpers, default_preloads: [:project]
3+
use CodeCorpsWeb.PreloadHelpers, default_preloads: ~w(project)a
44
use CodeCorpsWeb, :view
55
use JaSerializer.PhoenixView
66

77
attributes [:achieved, :amount, :current, :description]
88

9-
has_one :project, serializer: CodeCorpsWeb.ProjectView
9+
has_one :project, type: "project", field: :project_id
1010

1111
@doc """
1212
Determines whether the goal has been met by checking the amount against

lib/code_corps_web/views/github_app_installation_view.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
defmodule CodeCorpsWeb.GithubAppInstallationView do
22
@moduledoc false
3-
use CodeCorpsWeb.PreloadHelpers, default_preloads: ~w(github_repos organization_github_app_installations project user)a
3+
use CodeCorpsWeb.PreloadHelpers, default_preloads: ~w(github_repos organization_github_app_installations)a
44
use CodeCorpsWeb, :view
55
use JaSerializer.PhoenixView
66

77
attributes ~w(github_id github_account_id github_account_avatar_url github_account_login github_account_type inserted_at installed state updated_at)a
88

9-
has_one :project, serializer: CodeCorpsWeb.ProjectView
10-
has_one :user, serializer: CodeCorpsWeb.UserView
9+
has_one :project, type: "project", field: :project_id
10+
has_one :user, type: "user", field: :user_id
1111

1212
has_many :github_repos, serializer: CodeCorpsWeb.GithubRepoView, identifiers: :always
1313
has_many :organization_github_app_installations, serializer: CodeCorpsWeb.OrganizationGithubAppInstallationView, identifiers: :always
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
defmodule CodeCorpsWeb.GithubIssueView do
22
@moduledoc false
3-
use CodeCorpsWeb.PreloadHelpers,
4-
default_preloads: ~w(github_repo)a
53
use CodeCorpsWeb, :view
64
use JaSerializer.PhoenixView
75

@@ -11,5 +9,6 @@ defmodule CodeCorpsWeb.GithubIssueView do
119
:state, :title, :url
1210
]
1311

14-
has_one :github_repo, serializer: CodeCorpsWeb.GithubRepoView
12+
has_one :github_pull_request, type: "github-pull-request", field: :github_pull_request_id
13+
has_one :github_repo, type: "github-repo", field: :github_repo_id
1514
end
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
defmodule CodeCorpsWeb.GithubPullRequestView do
22
@moduledoc false
3-
use CodeCorpsWeb.PreloadHelpers, default_preloads: [:github_repo]
43
use CodeCorpsWeb, :view
54
use JaSerializer.PhoenixView
65

76
attributes [:github_created_at, :github_updated_at, :html_url, :merged, :number, :state]
87

9-
has_one :github_repo, serializer: CodeCorpsWeb.GithubRepoView
8+
has_one :github_repo, type: "github-repo", field: :github_repo_id
109
end
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
defmodule CodeCorpsWeb.GithubRepoView do
22
@moduledoc false
3-
use CodeCorpsWeb.PreloadHelpers, default_preloads: [:github_app_installation]
43
use CodeCorpsWeb, :view
54
use JaSerializer.PhoenixView
65

76
attributes [:github_account_avatar_url, :github_account_id,
87
:github_account_login, :github_account_type, :github_id, :inserted_at,
98
:name, :updated_at]
109

11-
has_one :github_app_installation, serializer: CodeCorpsWeb.GithubAppInstallationView
10+
has_one :github_app_installation, type: "github-app-installation", field: :github_app_installation_id
1211
end
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
defmodule CodeCorpsWeb.OrganizationGithubAppInstallationView do
22
@moduledoc false
3-
use CodeCorpsWeb.PreloadHelpers, default_preloads: [:github_app_installation, :organization]
43
use CodeCorpsWeb, :view
54
use JaSerializer.PhoenixView
65

76
attributes [:inserted_at, :updated_at]
87

9-
has_one :github_app_installation, serializer: CodeCorpsWeb.GithubAppInstallationView
10-
has_one :organization, serializer: CodeCorpsWeb.OrganizationView
8+
has_one :github_app_installation, type: "github-app-installation", field: :github_app_installation_id
9+
has_one :organization, type: "organization", field: :organization_id
1110
end

lib/code_corps_web/views/organization_view.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule CodeCorpsWeb.OrganizationView do
22
@moduledoc false
33
alias CodeCorps.Cloudex.CloudinaryUrl
4-
use CodeCorpsWeb.PreloadHelpers, default_preloads: [:organization_github_app_installations, :owner, :projects, :slugged_route, :stripe_connect_account]
4+
use CodeCorpsWeb.PreloadHelpers, default_preloads: [:organization_github_app_installations, :projects, :slugged_route, :stripe_connect_account]
55
use CodeCorpsWeb, :view
66
use JaSerializer.PhoenixView
77

@@ -10,7 +10,7 @@ defmodule CodeCorpsWeb.OrganizationView do
1010
:icon_large_url, :name, :slug, :inserted_at, :updated_at
1111
]
1212

13-
has_one :owner, serializer: CodeCorpsWeb.UserView
13+
has_one :owner, type: "user", field: :owner_id
1414
has_one :slugged_route, serializer: CodeCorpsWeb.SluggedRouteView
1515
has_one :stripe_connect_account, serializer: CodeCorpsWeb.StripeConnectAccountView
1616

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
defmodule CodeCorpsWeb.PreviewView do
22
@moduledoc false
3-
use CodeCorpsWeb.PreloadHelpers, default_preloads: [:user]
43
use CodeCorpsWeb, :view
54
use JaSerializer.PhoenixView
65

76
attributes [:markdown, :body, :inserted_at, :updated_at]
87

9-
has_one :user, serializer: CodeCorpsWeb.UserView
8+
has_one :user, type: "user", field: :user_id
109
end
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
defmodule CodeCorpsWeb.ProjectCategoryView do
22
@moduledoc false
3-
use CodeCorpsWeb.PreloadHelpers, default_preloads: [:project, :category]
43
use CodeCorpsWeb, :view
54
use JaSerializer.PhoenixView
65

7-
has_one :project, serializer: CodeCorpsWeb.ProjectView
8-
has_one :category, serializer: CodeCorpsWeb.CategoryView
6+
has_one :project, type: "project", field: :project_id
7+
has_one :category, type: "category", field: :category_id
98
end

0 commit comments

Comments
 (0)