smpallen99 / coherence

Coherence is a full featured, configurable authentication system for Phoenix
MIT License
1.27k stars 224 forks source link

How to preload association when loading user? #409

Closed jaimeiniesta closed 5 years ago

jaimeiniesta commented 5 years ago

In my app, the User module has a :subscriptions association that I need to preload.

How can I tell Coherence to preload this association when the user is authenticated?

mido18 commented 5 years ago

wow more than 1 month without solving and it's a basic need !

augnustin commented 5 years ago

:+1: same here.

Not even a hacky solution?

augnustin commented 5 years ago

Ok, found a hacky solution:

In web.ex, I add:

  def view do
      alias MyApp.Repo
  end

And in the view, before requiring the association, I add:

<% Repo.preload(Coherence.current_user(@conn), :my_association) %>

It is not so bad since it won't be loaded if this specific view is not required.

jaimeiniesta commented 5 years ago

For the records, I finally moved from Coherence to Pow - I'm super grateful to the author and all the contributors of Coherence but Pow is being actively maintained, so I'm closing this issue.

Please remember everyone that this is open source so we shouldn't complain because of open issues, let's try to build it together or start something else!

augnustin commented 5 years ago

Hi @jaimeiniesta

Thanks for getting back.

I don't think there has been complaints about open issue, simply worries about the current maintenance of the project, which appeared to be low and that you now confirmed drowned to zero, since even repo's author moved to another. :smile:

I reckon the most urgent thing to do is to inform the repo's visitors:

This project is currently un-maintained in favor of Pow.

Otherwise people using this dependency now are screwed.

jaimeiniesta commented 5 years ago

Hey @augnustin I'm not the author of Coherence, you may be mislead by the "author" label but it refers to this issue.

augnustin commented 5 years ago

Indeed :confused: