Suppose we have a map $f : \text{Spec }A\rightarrow X$, where $X$ is a scheme, $A$ a domain. Under what additional conditions is it true that $f$ factors through an inclusion $U\subset X$, where $U$ is an affine open?
I feel like this should be true quite generally, but I'm not sure how to approach this. The domain condition is to rule out examples where $X$ is nonaffine and $\text{Spec }A$ is a disjoint union of all the points of $X$.
I'm happy to assume $X$ is separated.