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.
