Thanks for your response.

I already had the 'tickets' attribute in the file class, defining it
as a join as you suggest.
I also use a custom reader in the view for listing the files, counting
all associated tickets.
Everything is working fine: i get the list of files, and each one with
the correct number of tickets. But when I click on the built-in 'sort'
feature for the 'tickets' column, I get the error.

I looked at the source code of the widget, but I don't understand most
of it right now.

Another thing I'm trying to do is generating a link for each cell in
the table with the ticket count, so that it takes the user to the list
of associated tickets for that file. I thought it should be done
with :present-as, but I have no idea how.

Anyway, I greatly appreciate any help.

On Mar 23, 12:38 am, Saikat Chakrabarti <[email protected]> wrote:
> Another thing I forgot to mention - if you are using clsql, you can
> have slots on your model that are of type join that reference all the
> associated objects.  This just makes the code a little cleaner (and
> you don't have to write as much SQL).  So, your model for file could
> be:
>
> (clsql:def-view-class file ()
>    ((id
>      :initarg :id
>      :accessor file-id
>      :type integer)
>     (name
>      :initarg :name
>      :accessor file-name
>      :type string)
>     (tickets
>       :accessor file-tickets
>       :db-kind :join
>       :db-info (:join-class ticket
>                     :home-key id
>                     :foreign-key file-id
>                     :set t)))
>
> Where your other model is called "ticket" and has slots for id (the
> ticket's id) and file-id (referencing the file the ticket is a part
> of).  Then, in your :reader lambda for your view, you can just sum the
> values in the list that you get from calling (file-tickets obj) and
> you don't need to write any clsql syntax stuff.
>
> On Mar 22, 7:31 pm, Saikat Chakrabarti <[email protected]> wrote:
>
> > 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