Re: join keys redux
Kevin Rosenberg <kevin-HJRc7zDS/[email protected]>
| Newsgroups | gmane.lisp.clsql.devel |
|---|---|
| Message-ID | <[email protected]> |
Cyrus Harmon wrote:
> 1. CLSQL def-view-class bug - we should fix the def-view-class stuff to
> allow for specifying lists for home-key and foreign key.
I look a look at tests/test-init.lisp. I do have a test view class
containing the following:
(employees
:reader company-employees
:db-kind :join
:db-info (:join-class employee
:home-key (companyid groupid)
:foreign-key (ecompanyid groupid)
:set t))))
You might want to look at the tests in the test suite that use that
view class.
> 2. spec'ing values for a join slot - I'm suggesting that in
> multi-column join, the join value could be specified by a (constant)
> value rather than a column name. Imagine tables person ( person_id,
> name ) and pet ( owner_id, animal_type, name ) and I want to make a
> slot for dogs (I know, there are other ways to do this, but bear with
> be and imagine that some nut job has thousands of cats and I just want
> dogs :-)) I could specify the join as :home-key '(:person-id 'dog)
> :foreign-key (:owner-id :animal_type) and get what I want.
Yes, I could see how you might have a view class such as DOG-OWNERS
and then you could just say
(select 'DOG-OWNERS)
But, isn't the much more common idiom something like
(select-animal-type-owners 'dog)
(defun select-animal-type-owners (a-type)
(select 'pet-owner-person :where [= [animal_type] a-type]))
This way you don't need to create a new view class every time you want
to select for a different animal type.
Kevin