To do this, should try adding a tickets slot to your file view that
doesn't map to your file model.  The way to get this to work is to
have a :reader for your ticket slot.  Thus, if your model is:

(clsql:def-view-class file ()
  ((id
    :initarg :id
    :accessor file-id
    :type integer)
   (name
    :initarg :name
    :accessor file-name
    :type string)))

you can have a view as follows:

(defview file-view (:inherit-from '(:scaffold file)
                             :type table)
  (tickets :reader (lambda (obj) (some-code-for-getting-total-
tickets)))

Here, "obj" passed into the :reader for tickets is a reference to your
file object, so you should be able to use that to construct some query
to get the total number of tickets for that file and have your lambda
return that.

Hope that helps.


On Mar 22, 5:54 am, Jose San Leandro <[email protected]>
wrote:
> Hi,
>
> I have a minimal db model with two tables: FILE and TICKET. A FILE is
> a collection of TICKETs, and a TICKET can only belong to one FILE. I'm
> pasting the relationship below, hoping you can see it using a fixed
> font.
>
>                            +------------------+                              
> +-------------------+
>                            |                  |                 X            
> |                   |
>                            |                  |1               / \
> N|                   |
>                            |      FILE        +<--------------X
> X=========>|              TICKET      |
>                            |                  |                \ /           
> |                   |
>                            |                  |                 X            
> |                   |
>                            +------------------+                              
> +-------------------+
>
> The FILE table doesn't contain an explicit column for the number of
> associated tickets. I don't want to denormalize the model if I can
> avoid it.
> I present the list of files in a datagrid, defining a new column
> 'tickets', with a custom :reader function, to display that information
> for each ticket. However, the built-in sort feature fails since it
> uses a generic way consisting of autogenerated sql queries, and that
> information is not explicit in the FILE table:
>
> While accessing database #<MYSQL-DATABASE localhost/prj/prj OPEN
> {B8FF6D9}>
>   with expression "SELECT FILE.NAME,FILE.ID,FILE.TICKETS FROM FILE
> ORDER BY FILE.TICKETS ASC LIMIT 6 OFFSET 0":
>   Error 1054 / Unknown column 'FILE.TICKETS' in 'field list'
>   has occurred.
>
> I just need a way to customize the generated query, in order to do the
> join myself and count the number of TICKETs pointing to each FILE. How
> can I override that query?
>
> Thank you in advance.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"weblocks" 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/weblocks?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to