refinerycms-blog icon indicating copy to clipboard operation
refinerycms-blog copied to clipboard

Upgrading to version 4 resulted in list of authors to no longer be available from the Posts form

Open dianaq12 opened this issue 7 years ago • 0 comments

The user class we are using does NOT have a username database column associated with it. A change made in the PostsController is the addition of the "find_all_authors" method which will only load authors if that database column exists. I don't think we should require developers to alter their database table used for authors simply to add this column to it. Especially if a similar column already exists with a different name. I think a better solution is checking to see if an attribute exists with that name. This way the developer just needs to add an attribute called username to their class which can then return the actual username stored in whatever column it currently is in. To make this work for me I created a PostsController decorator with the following find_all_authors method:

def find_all_authors
    @authors = Refinery::Blog.user_class.all if (!Refinery::Blog.user_class.nil? && Refinery::Blog.user_class.new.attributes.keys.include?('username'))
end

Then in my user class I simply do:

attribute :username
def username
    self.name
end

Not sure if you agree with this approach.... If you do I'm happy to do a PR for this change.

dianaq12 avatar Aug 29 '18 00:08 dianaq12