Associations and fields missing in schema -> Shouldn't they be kept separate? 🤔

This question regards the following warning:

warning: Please define the following association(s) in the schema for App.Context1.User:

belongs_to :invited_by, App.Context1.User
has_many :invited_users, App.Context1.User, [foreign_key: :invited_by_id]

It completely messes up the way I thought of contexts. I was under the impression that we are supposed to reuse certain fields in certain contexts. And other fields of the same database table in other contexts. Is that wrong?

Let me give you an example:
Why would my login context (passwords, invited_by, …) want anything to do with payment details or vice versa? Those are two different types of users in my understanding and therefore belong in different contexts.

By the way, this warning is being followed by another warning telling me to add some fields to the App.Context1.User which just don’t belong there.

Please help me understand this or let’s get rid of the warning.

What code is generating that warning?

You are using Pow right?

These warnings are triggered when the schema are missing certain fields that Pow would be expecting. If App.Context1.User is used with PowInvitation, then these assocs need to exist for the invitation logic to work.

The warnings will be printed when you use the use Pow.Ecto.Schema macro, so if you want to get rid of the warning then you’ll need to rewrite the module to not use the macro.

Yes, I’m using Pow. But Pow is using App.Context2.User. as defined in my config.exs with the key config :app, :pow, user: App.Context2.User. So why would my Context1.User show these warnings?

EDIT: Nevermind, I had accidentally copied a line in there.
use Pow.Extension.Ecto.Schema, extensions: [PowInvitation, PowPersistentSession, PowResetPassword]
This also explains why I couldn’t find the origin of the error message anywhere in the ecto Repo.

So sorry to have wasted your time.

1 Like