Wondering how I can specify a computed model attribute which is always 
returned for my model.

I would like to have an automatically computed sequence scoped on a column 
as follows:

DB[:table].select_append{row_number(:over, partition: owner_id, order: 
> created_at){}.as(:item_number)}.from_self


This returns the row_number as the item_number for all items scoped to 
owner_id, such that those numbers are monotonically increasing. It works 
perfectly.

I have tried to add the following in my model class:

set_dataset DB[:table].select_append{row_number(:over, partition: owner_id, 
> order: created_at){}.as(:item_number)}.from_self


But I get the following error:

sequel-4.6.0/lib/sequel/dataset/sql.rb:640:in `schema_and_table': 
> table_name should be a Symbol, SQL::QualifiedIdentifier, SQL::Identifier, 
> or String (Sequel::Error)

sequel-4.6.0/lib/sequel/database/schema_methods.rb:790:in `schema_and_table'
> sequel-4.6.0/lib/sequel/adapters/shared/postgres.rb:944:in `regclass_oid'
> sequel-4.6.0/lib/sequel/adapters/shared/postgres.rb:340:in `indexes'
> sequel-4.6.0/lib/sequel/plugins/auto_validations.rb:111:in 
> `setup_auto_validations'
> sequel-4.6.0/lib/sequel/model/plugins.rb:44:in `block in after_set_dataset'


Any ideas how I can have my models include a (read only) attribute computed 
from a window function? 

-- 
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 post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to