Since this method is returning the first result of the join query, or otherwise the first result of the matching documentation_url, you could change the assignment and return of the `dataset` local variable to:

    joins(:user).where(documentation_url: datasetUrl).order(User.arel_table[:email].matches(domain)).first || 
    where(documentation_url: datasetUrl).first

or, maybe to be a bit more legible, leave the assign the local variable and alter the return (getting rid of the if, and the extra return value):

    dataset || where(:documentation_url => datasetUrl).first