I have a resource called Post
, which has a many-to-many relationship with the Tag
resource. My relationship in the Post
resource is defined as follows:
many_to_many :tags, Tag do
through TagPost
source_attribute_on_join_resource :post_id
public? true
end
Whenever I load Tag
data for a Post
, I want the loaded tag data to be sorted based on a text
attribute from the Tag
resource. I have added the below line on the association in my post
resource. When I tried the below, the SQL order_by text
was applied to each individual Tag
rather than for the whole data. I keep getting the tags in different orders each time I load.
sort text: :asc
If the above method won’t work, Is there a way to sort the tags while using Ash.load
?
For example, in my action, I’m loading the tag data for my Post
resource as follows:
Ash.load(post, [:tags])
How can I add a sort here?