diff --git a/lib/groupher_server/cms/helper/macros.ex b/lib/groupher_server/cms/helper/macros.ex index 3c7ce4134..7b3f18075 100644 --- a/lib/groupher_server/cms/helper/macros.ex +++ b/lib/groupher_server/cms/helper/macros.ex @@ -5,7 +5,6 @@ defmodule GroupherServer.CMS.Helper.Macros do import Helper.Utils, only: [get_config: 2] alias GroupherServer.{CMS, Accounts} - alias Accounts.Model.User alias CMS.Model.{ @@ -32,7 +31,7 @@ defmodule GroupherServer.CMS.Helper.Macros do add(:post_id, references(:cms_posts, on_delete: :delete_all)) add(:job_id, references(:cms_jobs, on_delete: :delete_all)) - add(:repo_id, references(:cms_jobs, on_delete: :delete_all)) + add(:repo_id, references(:cms_repos, on_delete: :delete_all)) ... """ defmacro article_belongs_to_fields() do @@ -41,7 +40,7 @@ defmodule GroupherServer.CMS.Helper.Macros do quote do belongs_to( unquote(thread), - Module.concat(CMS.Model, unquote(thread) |> to_string |> Recase.to_pascal()), + Module.concat(CMS.Model, Recase.to_pascal(to_string(unquote(thread)))), foreign_key: unquote(:"#{thread}_id") ) end @@ -184,6 +183,7 @@ defmodule GroupherServer.CMS.Helper.Macros do """ defmacro general_article_fields do quote do + field(:title, :string) belongs_to(:author, Author) field(:views, :integer, default: 0) @@ -207,29 +207,6 @@ defmodule GroupherServer.CMS.Helper.Macros do end end - @doc """ - for GroupherServer.CMS.Model.Community - - # TABLE: "communities_[article]s" - add(:community_id, references(:communities, on_delete: :delete_all), null: false) - add(:[article]_id, references(:cms_[article]s, on_delete: :delete_all), null: false) - - create(unique_index(:communities_[article]s, [:community_id, :[article]_id])) - """ - defmacro community_article_fields() do - @article_threads - |> Enum.map(fn thread -> - quote do - many_to_many( - unquote(:"#{thread}s"), - Module.concat(CMS.Model, unquote(thread) |> to_string |> Recase.to_pascal()), - join_through: unquote("communities_#{to_string(thread)}s"), - join_keys: [community_id: :id] ++ Keyword.new([{unquote(:"#{thread}_id"), :id}]) - ) - end - end) - end - @doc """ for GroupherServer.CMS.[Article] @@ -237,7 +214,7 @@ defmodule GroupherServer.CMS.Helper.Macros do add(:community_id, references(:communities, on_delete: :delete_all), null: false) add(:[article]_id, references(:cms_[article]s, on_delete: :delete_all), null: false) - create(unique_index(:communities_job_[article]s, [:community_id, :[article]_id])) + create(unique_index(:communities_join_[article]s, [:community_id, :[article]_id])) """ defmacro article_communities_field(thread) do quote do diff --git a/lib/groupher_server/cms/models/community.ex b/lib/groupher_server/cms/models/community.ex index 86827062a..9edd3adda 100644 --- a/lib/groupher_server/cms/models/community.ex +++ b/lib/groupher_server/cms/models/community.ex @@ -70,8 +70,6 @@ defmodule GroupherServer.CMS.Model.Community do # on_replace: :delete ) - community_article_fields() - # # posts_block_list ... timestamps(type: :utc_datetime) end diff --git a/lib/groupher_server/cms/models/job.ex b/lib/groupher_server/cms/models/job.ex index 40d96146e..6bbc62b3b 100644 --- a/lib/groupher_server/cms/models/job.ex +++ b/lib/groupher_server/cms/models/job.ex @@ -19,7 +19,6 @@ defmodule GroupherServer.CMS.Model.Job do @type t :: %Job{} schema "cms_jobs" do - field(:title, :string) field(:company, :string) field(:company_link, :string) field(:desc, :string) diff --git a/lib/groupher_server/cms/models/post.ex b/lib/groupher_server/cms/models/post.ex index 78712950d..d71f7c826 100644 --- a/lib/groupher_server/cms/models/post.ex +++ b/lib/groupher_server/cms/models/post.ex @@ -23,7 +23,6 @@ defmodule GroupherServer.CMS.Model.Post do @type t :: %Post{} schema "cms_posts" do field(:body, :string) - field(:title, :string) field(:digest, :string) field(:link_addr, :string) field(:copy_right, :string) diff --git a/lib/groupher_server/cms/models/repo.ex b/lib/groupher_server/cms/models/repo.ex index ea86ea6a4..8d992ebd8 100644 --- a/lib/groupher_server/cms/models/repo.ex +++ b/lib/groupher_server/cms/models/repo.ex @@ -20,7 +20,6 @@ defmodule GroupherServer.CMS.Model.Repo do @type t :: %Repo{} schema "cms_repos" do - field(:title, :string) field(:owner_name, :string) field(:owner_url, :string) field(:repo_url, :string)