Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I do this search and order_by on a DBIx::Class::ResultSet
    primarykey
    data
    text
    <p><strong>Problem definition.</strong></p> <p>I have multiple clients with multiple users. Each client needs to be able to associate custom data with a user, search, and order by.</p> <hr> <p><strong>Database Solution:</strong></p> <p>A table Customfields which defines the customfields table. It has an id and name. It has a has_many relationship with a Userfields table (aka "attributes").</p> <p>The Userfields table has a userid, customfieldid, content and id. It belongs_to a Useraccounts table (aka "useraccount") and Customfields (aka "customfield")</p> <hr> <p><strong>Proposed select statement that I want:</strong></p> <p>This is a select statement that achieves and produces what I need.</p> <pre><code>SELECT ua.*, ( SELECT content FROM Userfields uf INNER JOIN Customfields cf ON cf.id = uf.customfieldid WHERE cf.name = 'Mothers birthdate' AND uf.uid=ua.uid ) AS 'Mothers birthdate', ( SELECT content FROM Userfields uf INNER JOIN Customfields cf ON cf.id = uf.customfieldid WHERE cf.name = 'Join Date' AND uf.uid=ua.uid ) AS 'Join Date' FROM UserAccounts ua ORDER BY 'Mothers birthdate'; </code></pre> <p>In this case their could be anything from 0 ... x sub select statements in the select statement and any one of them or none of them could be wanting to be ordered by.</p> <hr> <p><strong>Question</strong></p> <p>How do I achieve this with a ->search on my dbix class resultset or how do I achieve the same result with a search on my dbix class resultset?</p> <p>Here is how I usually select from my Useraccounts table, although I am unsure how to do the complex statement that I want to from here.</p> <pre><code>my @users = $db-&gt;resultset('Useraccounts')-&gt;search( undef, { page =&gt; $page, join =&gt; 'attributes', ... }); </code></pre> <p>Thanks for your time.</p> <p>-pdh</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload