Ah,
one_to_many :relateds, class: :Selection, dataset: (lambda do |r|
r.associated_dataset.where(Sequel.ilike(:path, "#{path}%"))
end)
*Worked!*
*Let me know if this is a wrong approach please.*
On Wednesday, February 17, 2021 at 4:14:14 AM UTC+3 [email protected]
wrote:
> Hi Jeremy,
>
> How can i filter Selection table based on entity's path field?
>
> selection = Selection[5]
>
> # I get selection id "5" from db.
>
> selection*.path* is varchar and "*Test*"
>
> I want to find all Selections that start with "Test%". Simply all relateds
> selections. So here is simple model:
>
> selecteds = Selection.where(Sequel.ilike(:path, "#{selection.path}%")).all
>
> Which works. But how can i make this in model?
>
> Something like:
>
> class Selection < Sequel::Model
> one_to_many :relateds, dataset: (lambda do |r|
> r.where(Sequel.ilike(:path, "#{path}%"))
> end)
> end
>
> Selection[5].relateds # <- here will list all selections that related to
> this.
>
> But it didn't worked.
>
>
>
>
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sequel-talk/704f86bd-b418-495e-9475-8eee0f9135d0n%40googlegroups.com.