Note that there are some explanatory texts on larger screens.

plurals
  1. POjoining on a subquery with dbix-class?
    primarykey
    data
    text
    <p>Given two tables: (incoming greatly reduced/simplified example that exhibits the key problem)</p> <p><strong>app_data</strong> represents applications that can be subscribed to</p> <pre><code>id app_name 1 apple 2 berry 3 cherry </code></pre> <p><strong>app_sub</strong> maps email addresses to applications</p> <pre><code>id email 1 alex 2 bob 2 coby </code></pre> <p>I'd like to generate a table from a single-user point-of-view showing which applications the current user is subscribed to and not.</p> <p>For example, from Alex's perspective I'd like to get:</p> <p><strong>desired_table</strong></p> <pre><code>id app_name is_subscribed 1 apple true 2 berry false 3 cherry false </code></pre> <p>The following pure SQL query seems to be fine:</p> <pre><code>select id, app_name, email from app_data left join ( select * from app_sub where email='alex' ) as subquery on app_name.id=app_data.id; </code></pre> <p>However I'm having great difficulty getting that to work in dbix-class.</p> <p>Alternatively, I tried to eliminate the subquery like so:</p> <pre><code>$app_data_resultset-&gt;search( { -or =&gt; [ { email =&gt; 'alex' }, { email =&gt; undef }, ], }, { select =&gt; [ qw{ me.id me.app_name app_sub.email }, ], as =&gt; [ qw{ id app_name email }, ], join =&gt; 'app_sub', ); </code></pre> <p>However, this (now expectedly) results in the following (after treating both 0 and null as false):</p> <p><strong>bad_table</strong></p> <pre><code>id app_name is_subscribed 1 apple true 3 cherry false </code></pre> <p>Since 'bob' and 'coby' are subscribed to id 2, the where clause completely eliminates the second id.</p> <p>Any help would be greatly appreciated!</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.
    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