On Tuesday, November 19, 2019 at 12:31:21 PM UTC-8, Jake wrote:
>
> I have some dataset_module methods defined within a model class.
>
> class Example
> dataset_module do
> def method_a
> where(...) // Standard where filter only using this table
> end
>
> def method_b
> join(:example_2, ...)
> .where(Sequel[:example_2][:some_column] => 'some_value')
> end
> end
> end
>
> If I call `Example.method_a.method_b.all` it returns an array of sort of
> modified instances of Example with the joined table's fields as well. Is
> there any way to keep the returned model instances as just normal instances
> of that model (as if nothing was joined)? I know you can do
> `select_all(:example)` within the method_b but if there is a column that is
> in both of these tables you cannot for example, call
> `Example.method_a.method_b.select(:duplicate_column)`.
>
You could try:
def method_b
join(:example_2, ...).
where(Sequel[:example_2][:some_column] => 'some_value').
select_all(:example).
from_self(:alias=>:example)
end
However, if you don't want to join, then why you are joining? You may be
better off using a subselect:
def method_b
where(:fk=>db[:example_2].select(:pk).where(some_column: 'some_value'))
end
For appropriate values of :fk and :pk.
Thanks,
Jeremy
--
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/edaf3739-a01c-48b4-87b4-887904056519%40googlegroups.com.