activerecord
activerecord copied to clipboard
Conditional join?
Hey,
This is more of a support ticket than an issue. I'm running a query that includes a join. As expected, when the join value is blank, it does not return a result. However, in my case, I want to allow that -- so that the rest of the values in the result still populate. Could you maybe provide me some advice? I'm using the exp:vz_tabular:csv
to get this data into a csv. The join that is needed to be 'conditional' or 'eligible to be blank' is join:exp_channel_titles="exp_forms_entries.fid_1068 = exp_channel_titles.entry_id"
. Thanks for any advice!
{exp:vz_tabular:csv filename="wart-haig-waiver.csv"}
{exp:activerecord
select="
exp_forms_entries.fentry_id,
exp_channel_data.field_id_696,
exp_channel_data.field_id_679,
exp_forms_entries.fid_1037,
exp_forms_entries.fid_1031,
exp_forms_entries.date,
exp_forms_entries.fid_1128,
exp_forms_entries.fid_1029,
exp_channel_data.field_id_718,
exp_channel_data.field_id_719,
exp_channel_data.field_id_452,
exp_forms_entries.fid_1068,
exp_forms_entries.fid_1037,
exp_channel_titles.title,
exp_members.email"
from="exp_forms_entries"
where:exp_forms_entries.form_id="37"
join:exp_channel_titles="exp_forms_entries.fid_1068 = exp_channel_titles.entry_id"
join:exp_channel_data="exp_forms_entries.fid_1067 = exp_channel_data.entry_id"
join:exp_members="exp_forms_entries.member_id = exp_members.member_id"
{if get:event_name != ''}
like:exp_forms_entries.fid_1037="{get:event_name}"
{/if}
}
[col Entry ID]{fentry_id}[/col]
[col Date]{date format="%m-%d-%y"}[/col]
[col First Name]{field_id_718}[/col]
[col Last Name]{field_id_719}[/col]
[col Email]{email}[/col]
[col Address]{field_id_696}[/col]
[col Role]participant[/col]
[col Sport]{fid_1031}[/col]
[col Gender]{field_id_679}[/col]
[col Grad Year]{field_id_452}[/col]
[col Coach's Name]{fid_1128}[/col]
[col Coach's Email]{fid_1129}[/col]
[col Club]{title}[/col]
[col Event]{fid_1037}[/col]
{/exp:activerecord}
{/exp:vz_tabular:csv}
I think what you're looking for is left_join
instead of join
exactly what I was looking for! Thanks so much. This is great.