Thank you, it worked. Now I understand. Saw the method definition here now:
https://github.com/jeremyevans/sequel/blob/ab14b863e30b2672a3614f455e0e4ea41632b961/lib/sequel/model/base.rb#L776
But it is not applying filter on the query when I make dataset out of query
using <model_class>.fetch(Query) and apply filter like:
`dataset.where(::Sequel.lit("#{column_table_name}.#{column} >= ?",
min_value))` or `dataset.where(::Sequel.lit("#{column_table_name}.#{column}
<= ?", max_value))`
Thanks,
Sudhanshu Kumar Singh
On Mon, Aug 12, 2019 at 5:59 PM Jeremy Evans <[email protected]> wrote:
> On Monday, August 12, 2019 at 8:19:03 AM UTC-7, Sudhanshu Kumar Singh
> wrote:
>>
>> Hi Everyone,
>> I added this query and added attr_accessor "balance_amount" and
>> "booking_customer_id" in customers table, my query sets the value on
>> attribute accessor but I am not able to fetch it from the dataset result,
>> the query is:
>>
>> SELECT * from customers
>>> LEFT JOIN
>>> (
>>> SELECT cr.booking_customer_id, current_balance -
>>> coalesce(booking_amount, 0) as balance_amount
>>> FROM (Distinct record from table 2, i.e. bookings) cr
>>> RIGHT JOIN (Distinct record from table 3, e.g. balance) cb
>>> ON (booking_customer_id = balance_customer_id)
>>> ) cwr
>>> ON (customers.id = cwr.bookings_customer_id)
>>
>>
>> when I do, dataset.all and It shows `balance_amount` in the
>> results, try to fetch like: `dataset.all.first.balance_amount` it
>> returns nil. What am I doing wrong here?
>>
>
> attr_accessor will look and store the attribute value in an instance
> variable. That is not where Sequel stores values for model instances. Use
> def_column_accessor instead of attr_accessor.
>
> 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/59470928-ca87-4467-a247-2eb5f34a3eec%40googlegroups.com
> <https://groups.google.com/d/msgid/sequel-talk/59470928-ca87-4467-a247-2eb5f34a3eec%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
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/CAJzrcYRFpg%3DbtOPC5MGnLaX3n4sVD4g8kYXbjU5dDFUO3ffo3w%40mail.gmail.com.