Hi Jeremy,
I wasn't clear enough. I do not need validations on the associated
objects. I simply need to require at least one association (e.g. a
minimum of one keyword). I currently have the following workaround,
where I create accessors using *_ids and then, within the model, call
the *_pks methods in the after_create hook.
class Collection < Sequel::Model
plugin :validation_helpers
plugin :association_pks
many_to_one :category
many_to_one :language
many_to_many :keywords
many_to_many :authors, class: User, right_key: :user_id
attr_accessor :keyword_ids, :author_ids
def validate
super
validates_presence
[:title, :description, :copyright, :category_id, :language_id, :keyword_ids,
:author_ids]
validates_length_range 1..255, [:title, :description]
validates_format /\d{4}/, :copyright
end
def after_save
self.keyword_pks = keyword_ids
self.author_pks = author_ids
end
end
My controller action then looks like this:
@collection = Collection.new
@collection.update_only params,
[:title, :description, :copyright, :category_id, :language_id, :published,
:author_ids, :keyword_ids]
Jamie
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.