[Dbix-class] has_many and count
Jesper Krogh
jesper at krogh.cc
Mon Aug 7 13:56:18 CEST 2006
Hi.
I cant get DBIx::Class og make this query.. I have a table with a has_many
relation.
Company has many Persons, that has many projects..
Company (id,name,address).
Person (id,company_id,name,address)
Projects (id,person_id,name)
I'd like to create a view that list persons with their company name and their
project-count and be sortable in the database on both elements from the
company-table and the count from the projects table.
I bumped into "distinct => 1" but when I add "+select =>
[\'count(projects.projectid')] it tries to group by this element, which
the
database complains about.
An example output:
Company_id,Cname, Caddress, Pid, Pname, Paddres, Count
1,test,test2,2,Jesper,Krogh,7
1,test,test2,3,Test,Test2,3
Getting data from the company table is "quite-easy" just putting it into
the "prefetch" => [qw/company/], but the "has_many group by count stuff is
"harder".
Any suggestions?
Jesper
--
Jesper Krogh
More information about the Dbix-class
mailing list