Skip to content

Instantly share code, notes, and snippets.

@aleandros
Last active March 22, 2017 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aleandros/027418c3a6062f9971027ed2cf494e3a to your computer and use it in GitHub Desktop.
Save aleandros/027418c3a6062f9971027ed2cf494e3a to your computer and use it in GitHub Desktop.
Ecto model relationships with non-default column names
defmodule MyApp.User do
use MyApp.Web, :model
@primary_key {:UserId, :id, autogenerate: true}
schema "user" do
has_one :credential, MyApp.Credential,
foreign_key: :UserId,
references: :UserId
many_to_many :roles, MyApp.Role,
join_through: MyApp.UserRole,
join_keys: [UserId: :UserId, RoleId: :RoleId]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment