activerecord icon indicating copy to clipboard operation
activerecord copied to clipboard

Field values equal to each other

Open colinambler opened this issue 9 years ago • 7 comments
trafficstars

Great plugin!

Here's my code and you'll see what I'm trying to do:

where:exp_forms_entries.member_id="{member_id}"
or_where:exp_forms_entries.fid_1010="exp_forms_entries.fentry_id"

It's evaluating the "exp_forms_entries.fentry_id" as a string, rather than database field. Possible?

colinambler avatar Apr 21 '16 06:04 colinambler

Can you try this?

where:exp_forms_entries.member_id="{member_id}"
or_where[]="exp_forms_entries.fid_1010 = exp_forms_entries.fentry_id"

rsanchez avatar Apr 21 '16 13:04 rsanchez

Don't think it worked...here's query:

screen shot 2016-04-21 at 8 08 20 am

colinambler avatar Apr 21 '16 13:04 colinambler

Maybe it's too early in the morning for me, but that query looks right. Or am I missing something?

rsanchez avatar Apr 21 '16 13:04 rsanchez

Ok, you're right! Computer is doing what I told it to do...not what I want it to do. See attached. I went to the database and ran the same query there for checks. See attached. I'm trying to find where two separate entries have the same id, in different columns.

screen shot 2016-04-21 at 8 30 14 am

colinambler avatar Apr 21 '16 13:04 colinambler

So, after doing some digging, what I'm trying to do is a subquery. Here's the actual query that I want to perform. Is is possible with your plugin?

SELECT `exp_forms_entries`.`form_id`, exp_forms_entries.fid_1002, exp_forms_entries.fid_1010, exp_forms_entries.fentry_id, exp_forms.form_title
FROM (`exp_forms_entries`)
INNER JOIN `exp_forms` ON `exp_forms_entries`.`form_id` = `exp_forms`.`form_id`
WHERE `exp_forms_entries`.`member_id` =  2
OR exp_forms_entries.fid_1010 IN (SELECT fentry_id from exp_forms_entries )

note: member_id would be passed-in as a variable

colinambler avatar Apr 21 '16 19:04 colinambler

I think or_where[]="exp_forms_entries.fid_1010 IN (SELECT fentry_id from exp_forms_entries )" would work.

rsanchez avatar Apr 21 '16 19:04 rsanchez

worked!! You da man! This is best plugin ever.

colinambler avatar Apr 21 '16 19:04 colinambler