You need to add parentheses to resolve ambiguity. I tend to add them around the whole from, like so:
expect = from(
j in Test.JoinModel,
join: e in assoc(j, :example),
preload: [example: from(w in Test.WhereModel, limit: ^3 , offset: ^0)]
)
Strictly speaking only the parentheses around the inner from are required, because without them Elixir doesn’t know if you are adding more options for the from or the preload.
Thanks for you reply .It still throws an error. This time this one:
from(w in Test.WhereModel, limit: 3, offset: 0)` is not a valid preload expression. preload expects an atom,a list of atoms or a keyword list with more preloads as values. Use ^ on the outermost preload to interpolate a value
Note: keep in mind operations like limit and offset in the preload query will affect the whole result set and not each association. For example, the query below:
comments_query = from c in Comment, order_by: c.popularity, limit: 5
Repo.all from p in Post, preload: [comments: ^comments_query]
won’t bring the top of comments per post. Rather, it will only bring the 5 top comments across all posts.