Rails 5 LEFT OUTER JOIN includes records outside of condition
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
This is driving me crazy, and I'd like a separate pair of eyes on it. I have the following models:
class Client
has_many: client_orders
end
class ClientOrders
belongs_to :client
end
Now, I'm trying to get only orders for clients created in the past 30 days. So I write this:
time_range = (30.days.ago - 1.day)..Time.now.midnight
@clients = Client.left_outer_joins(:client_orders).where( client_orders: { created_at: time_range } )
I feel that logic is correct. Now, the following happens:
I write: @clients.first.client_orders.first
And the very first record is this:
=> #<ClientOrder:0x00007f364764b3b8
id: 1,
client_order_number: "25970",
status: "pending",
client_id: 3,
client_user_id: 8,
shipping_cost_cents: 287,
shipping_cost_currency: "USD",
taxes_cents: 8800,
taxes_currency: "USD",
created_at: Fri, 16 Feb 2018 00:00:00 UTC +00:00,
updated_at: Mon, 31 Dec 2018 21:51:54 UTC +00:00,
subtotal_cents: 3426500,
subtotal_currency: "USD",
quickbooks_id: nil,
sync_token: nil,
convenience_fee_cents: 0,
convenience_fee_currency: "USD">
Notice the created_at
date? Now, what's really funny, is if I do this:
@clients.first.client_orders.first.created_at === time_range
D, [2019-01-03T06:28:53.885281 #1] DEBUG -- : CACHE ClientOrder Load (0.0ms) SELECT "client_orders".* FROM "client_orders" WHERE "client_orders"."client_id" = $1 ORDER BY "client_orders"."id" ASC LIMIT $2 [["client_id", 3], ["LIMIT", 1]]
D, [2019-01-03T06:28:53.886633 #1] DEBUG -- : ↳ (pry):7
=> false
So what the heck? Is there something in erb
that does something funky so it's including records that shouldn't be when it actually runs or something? I've tried using other variables to store the query in in case it's including data from a previous query or something but that doesn't make a difference.
So, yeah, my goal is to an object that only contains the past 30 days worth of orders.
BONUS POINTS: Get the clients who DON'T have orders in the past 30 days. That I'm not quite sure about how to pull off. I was thinking something like this: @clients = Client.where('id NOT IN (SELECT DISTINCT(client_id) FROM client_orders)')
ruby-on-rails ruby-on-rails-5 left-join
add a comment |
This is driving me crazy, and I'd like a separate pair of eyes on it. I have the following models:
class Client
has_many: client_orders
end
class ClientOrders
belongs_to :client
end
Now, I'm trying to get only orders for clients created in the past 30 days. So I write this:
time_range = (30.days.ago - 1.day)..Time.now.midnight
@clients = Client.left_outer_joins(:client_orders).where( client_orders: { created_at: time_range } )
I feel that logic is correct. Now, the following happens:
I write: @clients.first.client_orders.first
And the very first record is this:
=> #<ClientOrder:0x00007f364764b3b8
id: 1,
client_order_number: "25970",
status: "pending",
client_id: 3,
client_user_id: 8,
shipping_cost_cents: 287,
shipping_cost_currency: "USD",
taxes_cents: 8800,
taxes_currency: "USD",
created_at: Fri, 16 Feb 2018 00:00:00 UTC +00:00,
updated_at: Mon, 31 Dec 2018 21:51:54 UTC +00:00,
subtotal_cents: 3426500,
subtotal_currency: "USD",
quickbooks_id: nil,
sync_token: nil,
convenience_fee_cents: 0,
convenience_fee_currency: "USD">
Notice the created_at
date? Now, what's really funny, is if I do this:
@clients.first.client_orders.first.created_at === time_range
D, [2019-01-03T06:28:53.885281 #1] DEBUG -- : CACHE ClientOrder Load (0.0ms) SELECT "client_orders".* FROM "client_orders" WHERE "client_orders"."client_id" = $1 ORDER BY "client_orders"."id" ASC LIMIT $2 [["client_id", 3], ["LIMIT", 1]]
D, [2019-01-03T06:28:53.886633 #1] DEBUG -- : ↳ (pry):7
=> false
So what the heck? Is there something in erb
that does something funky so it's including records that shouldn't be when it actually runs or something? I've tried using other variables to store the query in in case it's including data from a previous query or something but that doesn't make a difference.
So, yeah, my goal is to an object that only contains the past 30 days worth of orders.
BONUS POINTS: Get the clients who DON'T have orders in the past 30 days. That I'm not quite sure about how to pull off. I was thinking something like this: @clients = Client.where('id NOT IN (SELECT DISTINCT(client_id) FROM client_orders)')
ruby-on-rails ruby-on-rails-5 left-join
@clients.first.client_orders.first.created_at === time_range will not be true because where executes within query and you are trying to check equality.
– wasipeer
Jan 3 at 6:49
time_range.include?(@clients.first.client_orders.first.created_at) try this it will be true. so the problem is in the === statement and has nothing to do with join
– wasipeer
Jan 3 at 6:56
I tried that, and it still came out false: [78] pry(#<AccountManagementsController>)> time_range.include?(@clients.first.client_orders.first.created_at) D, [2019-01-03T07:09:00.695526 #1] DEBUG -- : CACHE ClientOrder Load (0.0ms) SELECT "client_orders".* FROM "client_orders" WHERE "client_orders"."client_id" = $1 ORDER BY "client_orders"."id" ASC LIMIT $2 [["client_id", 3], ["LIMIT", 1]] D, [2019-01-03T07:09:00.696902 #1] DEBUG -- : ↳ (pry):46 => false
– Jason Shultz
Jan 3 at 7:09
another issue is in time_range = (30.days.ago - 1.day)..Time.now.midnight. try this
– wasipeer
Jan 3 at 7:12
add a comment |
This is driving me crazy, and I'd like a separate pair of eyes on it. I have the following models:
class Client
has_many: client_orders
end
class ClientOrders
belongs_to :client
end
Now, I'm trying to get only orders for clients created in the past 30 days. So I write this:
time_range = (30.days.ago - 1.day)..Time.now.midnight
@clients = Client.left_outer_joins(:client_orders).where( client_orders: { created_at: time_range } )
I feel that logic is correct. Now, the following happens:
I write: @clients.first.client_orders.first
And the very first record is this:
=> #<ClientOrder:0x00007f364764b3b8
id: 1,
client_order_number: "25970",
status: "pending",
client_id: 3,
client_user_id: 8,
shipping_cost_cents: 287,
shipping_cost_currency: "USD",
taxes_cents: 8800,
taxes_currency: "USD",
created_at: Fri, 16 Feb 2018 00:00:00 UTC +00:00,
updated_at: Mon, 31 Dec 2018 21:51:54 UTC +00:00,
subtotal_cents: 3426500,
subtotal_currency: "USD",
quickbooks_id: nil,
sync_token: nil,
convenience_fee_cents: 0,
convenience_fee_currency: "USD">
Notice the created_at
date? Now, what's really funny, is if I do this:
@clients.first.client_orders.first.created_at === time_range
D, [2019-01-03T06:28:53.885281 #1] DEBUG -- : CACHE ClientOrder Load (0.0ms) SELECT "client_orders".* FROM "client_orders" WHERE "client_orders"."client_id" = $1 ORDER BY "client_orders"."id" ASC LIMIT $2 [["client_id", 3], ["LIMIT", 1]]
D, [2019-01-03T06:28:53.886633 #1] DEBUG -- : ↳ (pry):7
=> false
So what the heck? Is there something in erb
that does something funky so it's including records that shouldn't be when it actually runs or something? I've tried using other variables to store the query in in case it's including data from a previous query or something but that doesn't make a difference.
So, yeah, my goal is to an object that only contains the past 30 days worth of orders.
BONUS POINTS: Get the clients who DON'T have orders in the past 30 days. That I'm not quite sure about how to pull off. I was thinking something like this: @clients = Client.where('id NOT IN (SELECT DISTINCT(client_id) FROM client_orders)')
ruby-on-rails ruby-on-rails-5 left-join
This is driving me crazy, and I'd like a separate pair of eyes on it. I have the following models:
class Client
has_many: client_orders
end
class ClientOrders
belongs_to :client
end
Now, I'm trying to get only orders for clients created in the past 30 days. So I write this:
time_range = (30.days.ago - 1.day)..Time.now.midnight
@clients = Client.left_outer_joins(:client_orders).where( client_orders: { created_at: time_range } )
I feel that logic is correct. Now, the following happens:
I write: @clients.first.client_orders.first
And the very first record is this:
=> #<ClientOrder:0x00007f364764b3b8
id: 1,
client_order_number: "25970",
status: "pending",
client_id: 3,
client_user_id: 8,
shipping_cost_cents: 287,
shipping_cost_currency: "USD",
taxes_cents: 8800,
taxes_currency: "USD",
created_at: Fri, 16 Feb 2018 00:00:00 UTC +00:00,
updated_at: Mon, 31 Dec 2018 21:51:54 UTC +00:00,
subtotal_cents: 3426500,
subtotal_currency: "USD",
quickbooks_id: nil,
sync_token: nil,
convenience_fee_cents: 0,
convenience_fee_currency: "USD">
Notice the created_at
date? Now, what's really funny, is if I do this:
@clients.first.client_orders.first.created_at === time_range
D, [2019-01-03T06:28:53.885281 #1] DEBUG -- : CACHE ClientOrder Load (0.0ms) SELECT "client_orders".* FROM "client_orders" WHERE "client_orders"."client_id" = $1 ORDER BY "client_orders"."id" ASC LIMIT $2 [["client_id", 3], ["LIMIT", 1]]
D, [2019-01-03T06:28:53.886633 #1] DEBUG -- : ↳ (pry):7
=> false
So what the heck? Is there something in erb
that does something funky so it's including records that shouldn't be when it actually runs or something? I've tried using other variables to store the query in in case it's including data from a previous query or something but that doesn't make a difference.
So, yeah, my goal is to an object that only contains the past 30 days worth of orders.
BONUS POINTS: Get the clients who DON'T have orders in the past 30 days. That I'm not quite sure about how to pull off. I was thinking something like this: @clients = Client.where('id NOT IN (SELECT DISTINCT(client_id) FROM client_orders)')
ruby-on-rails ruby-on-rails-5 left-join
ruby-on-rails ruby-on-rails-5 left-join
asked Jan 3 at 6:41


Jason ShultzJason Shultz
5671432
5671432
@clients.first.client_orders.first.created_at === time_range will not be true because where executes within query and you are trying to check equality.
– wasipeer
Jan 3 at 6:49
time_range.include?(@clients.first.client_orders.first.created_at) try this it will be true. so the problem is in the === statement and has nothing to do with join
– wasipeer
Jan 3 at 6:56
I tried that, and it still came out false: [78] pry(#<AccountManagementsController>)> time_range.include?(@clients.first.client_orders.first.created_at) D, [2019-01-03T07:09:00.695526 #1] DEBUG -- : CACHE ClientOrder Load (0.0ms) SELECT "client_orders".* FROM "client_orders" WHERE "client_orders"."client_id" = $1 ORDER BY "client_orders"."id" ASC LIMIT $2 [["client_id", 3], ["LIMIT", 1]] D, [2019-01-03T07:09:00.696902 #1] DEBUG -- : ↳ (pry):46 => false
– Jason Shultz
Jan 3 at 7:09
another issue is in time_range = (30.days.ago - 1.day)..Time.now.midnight. try this
– wasipeer
Jan 3 at 7:12
add a comment |
@clients.first.client_orders.first.created_at === time_range will not be true because where executes within query and you are trying to check equality.
– wasipeer
Jan 3 at 6:49
time_range.include?(@clients.first.client_orders.first.created_at) try this it will be true. so the problem is in the === statement and has nothing to do with join
– wasipeer
Jan 3 at 6:56
I tried that, and it still came out false: [78] pry(#<AccountManagementsController>)> time_range.include?(@clients.first.client_orders.first.created_at) D, [2019-01-03T07:09:00.695526 #1] DEBUG -- : CACHE ClientOrder Load (0.0ms) SELECT "client_orders".* FROM "client_orders" WHERE "client_orders"."client_id" = $1 ORDER BY "client_orders"."id" ASC LIMIT $2 [["client_id", 3], ["LIMIT", 1]] D, [2019-01-03T07:09:00.696902 #1] DEBUG -- : ↳ (pry):46 => false
– Jason Shultz
Jan 3 at 7:09
another issue is in time_range = (30.days.ago - 1.day)..Time.now.midnight. try this
– wasipeer
Jan 3 at 7:12
@clients.first.client_orders.first.created_at === time_range will not be true because where executes within query and you are trying to check equality.
– wasipeer
Jan 3 at 6:49
@clients.first.client_orders.first.created_at === time_range will not be true because where executes within query and you are trying to check equality.
– wasipeer
Jan 3 at 6:49
time_range.include?(@clients.first.client_orders.first.created_at) try this it will be true. so the problem is in the === statement and has nothing to do with join
– wasipeer
Jan 3 at 6:56
time_range.include?(@clients.first.client_orders.first.created_at) try this it will be true. so the problem is in the === statement and has nothing to do with join
– wasipeer
Jan 3 at 6:56
I tried that, and it still came out false: [78] pry(#<AccountManagementsController>)> time_range.include?(@clients.first.client_orders.first.created_at) D, [2019-01-03T07:09:00.695526 #1] DEBUG -- : CACHE ClientOrder Load (0.0ms) SELECT "client_orders".* FROM "client_orders" WHERE "client_orders"."client_id" = $1 ORDER BY "client_orders"."id" ASC LIMIT $2 [["client_id", 3], ["LIMIT", 1]] D, [2019-01-03T07:09:00.696902 #1] DEBUG -- : ↳ (pry):46 => false
– Jason Shultz
Jan 3 at 7:09
I tried that, and it still came out false: [78] pry(#<AccountManagementsController>)> time_range.include?(@clients.first.client_orders.first.created_at) D, [2019-01-03T07:09:00.695526 #1] DEBUG -- : CACHE ClientOrder Load (0.0ms) SELECT "client_orders".* FROM "client_orders" WHERE "client_orders"."client_id" = $1 ORDER BY "client_orders"."id" ASC LIMIT $2 [["client_id", 3], ["LIMIT", 1]] D, [2019-01-03T07:09:00.696902 #1] DEBUG -- : ↳ (pry):46 => false
– Jason Shultz
Jan 3 at 7:09
another issue is in time_range = (30.days.ago - 1.day)..Time.now.midnight. try this
– wasipeer
Jan 3 at 7:12
another issue is in time_range = (30.days.ago - 1.day)..Time.now.midnight. try this
– wasipeer
Jan 3 at 7:12
add a comment |
1 Answer
1
active
oldest
votes
I think you should declare something like these
time_range = (Time.now.midnight - 30.days)..Time.now.midnight
@clients = Client.left_outer_joins(:client_orders).where( client_orders: { created_at: time_range } )
I think I'm starting to understand what's happening. Is there a way I can reverse that query so it shows clients who don't have orders in that time frame?
– Jason Shultz
Jan 3 at 8:39
Yes simply you can used @clients = Client.left_outer_joins(:client_orders).where.not( client_orders: { created_at: time_range } )
– Cryptex Technologies
Jan 3 at 8:40
For some reason that doesn't work? I try this: time_range = (Time.now.midnight - 30.days)..Time.now.midnight @clients = Client.left_outer_joins(:client_orders).where.not( client_orders: { created_at: time_range } ).distinct And it still shows clients with orders in the past couple of days?
– Jason Shultz
Jan 3 at 8:49
@JasonShultz please check your time zone format the same query does work for me
– Cryptex Technologies
Jan 3 at 9:44
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54017473%2frails-5-left-outer-join-includes-records-outside-of-condition%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think you should declare something like these
time_range = (Time.now.midnight - 30.days)..Time.now.midnight
@clients = Client.left_outer_joins(:client_orders).where( client_orders: { created_at: time_range } )
I think I'm starting to understand what's happening. Is there a way I can reverse that query so it shows clients who don't have orders in that time frame?
– Jason Shultz
Jan 3 at 8:39
Yes simply you can used @clients = Client.left_outer_joins(:client_orders).where.not( client_orders: { created_at: time_range } )
– Cryptex Technologies
Jan 3 at 8:40
For some reason that doesn't work? I try this: time_range = (Time.now.midnight - 30.days)..Time.now.midnight @clients = Client.left_outer_joins(:client_orders).where.not( client_orders: { created_at: time_range } ).distinct And it still shows clients with orders in the past couple of days?
– Jason Shultz
Jan 3 at 8:49
@JasonShultz please check your time zone format the same query does work for me
– Cryptex Technologies
Jan 3 at 9:44
add a comment |
I think you should declare something like these
time_range = (Time.now.midnight - 30.days)..Time.now.midnight
@clients = Client.left_outer_joins(:client_orders).where( client_orders: { created_at: time_range } )
I think I'm starting to understand what's happening. Is there a way I can reverse that query so it shows clients who don't have orders in that time frame?
– Jason Shultz
Jan 3 at 8:39
Yes simply you can used @clients = Client.left_outer_joins(:client_orders).where.not( client_orders: { created_at: time_range } )
– Cryptex Technologies
Jan 3 at 8:40
For some reason that doesn't work? I try this: time_range = (Time.now.midnight - 30.days)..Time.now.midnight @clients = Client.left_outer_joins(:client_orders).where.not( client_orders: { created_at: time_range } ).distinct And it still shows clients with orders in the past couple of days?
– Jason Shultz
Jan 3 at 8:49
@JasonShultz please check your time zone format the same query does work for me
– Cryptex Technologies
Jan 3 at 9:44
add a comment |
I think you should declare something like these
time_range = (Time.now.midnight - 30.days)..Time.now.midnight
@clients = Client.left_outer_joins(:client_orders).where( client_orders: { created_at: time_range } )
I think you should declare something like these
time_range = (Time.now.midnight - 30.days)..Time.now.midnight
@clients = Client.left_outer_joins(:client_orders).where( client_orders: { created_at: time_range } )
edited Jan 3 at 9:51
answered Jan 3 at 8:09
Cryptex TechnologiesCryptex Technologies
810213
810213
I think I'm starting to understand what's happening. Is there a way I can reverse that query so it shows clients who don't have orders in that time frame?
– Jason Shultz
Jan 3 at 8:39
Yes simply you can used @clients = Client.left_outer_joins(:client_orders).where.not( client_orders: { created_at: time_range } )
– Cryptex Technologies
Jan 3 at 8:40
For some reason that doesn't work? I try this: time_range = (Time.now.midnight - 30.days)..Time.now.midnight @clients = Client.left_outer_joins(:client_orders).where.not( client_orders: { created_at: time_range } ).distinct And it still shows clients with orders in the past couple of days?
– Jason Shultz
Jan 3 at 8:49
@JasonShultz please check your time zone format the same query does work for me
– Cryptex Technologies
Jan 3 at 9:44
add a comment |
I think I'm starting to understand what's happening. Is there a way I can reverse that query so it shows clients who don't have orders in that time frame?
– Jason Shultz
Jan 3 at 8:39
Yes simply you can used @clients = Client.left_outer_joins(:client_orders).where.not( client_orders: { created_at: time_range } )
– Cryptex Technologies
Jan 3 at 8:40
For some reason that doesn't work? I try this: time_range = (Time.now.midnight - 30.days)..Time.now.midnight @clients = Client.left_outer_joins(:client_orders).where.not( client_orders: { created_at: time_range } ).distinct And it still shows clients with orders in the past couple of days?
– Jason Shultz
Jan 3 at 8:49
@JasonShultz please check your time zone format the same query does work for me
– Cryptex Technologies
Jan 3 at 9:44
I think I'm starting to understand what's happening. Is there a way I can reverse that query so it shows clients who don't have orders in that time frame?
– Jason Shultz
Jan 3 at 8:39
I think I'm starting to understand what's happening. Is there a way I can reverse that query so it shows clients who don't have orders in that time frame?
– Jason Shultz
Jan 3 at 8:39
Yes simply you can used @clients = Client.left_outer_joins(:client_orders).where.not( client_orders: { created_at: time_range } )
– Cryptex Technologies
Jan 3 at 8:40
Yes simply you can used @clients = Client.left_outer_joins(:client_orders).where.not( client_orders: { created_at: time_range } )
– Cryptex Technologies
Jan 3 at 8:40
For some reason that doesn't work? I try this: time_range = (Time.now.midnight - 30.days)..Time.now.midnight @clients = Client.left_outer_joins(:client_orders).where.not( client_orders: { created_at: time_range } ).distinct And it still shows clients with orders in the past couple of days?
– Jason Shultz
Jan 3 at 8:49
For some reason that doesn't work? I try this: time_range = (Time.now.midnight - 30.days)..Time.now.midnight @clients = Client.left_outer_joins(:client_orders).where.not( client_orders: { created_at: time_range } ).distinct And it still shows clients with orders in the past couple of days?
– Jason Shultz
Jan 3 at 8:49
@JasonShultz please check your time zone format the same query does work for me
– Cryptex Technologies
Jan 3 at 9:44
@JasonShultz please check your time zone format the same query does work for me
– Cryptex Technologies
Jan 3 at 9:44
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54017473%2frails-5-left-outer-join-includes-records-outside-of-condition%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
@clients.first.client_orders.first.created_at === time_range will not be true because where executes within query and you are trying to check equality.
– wasipeer
Jan 3 at 6:49
time_range.include?(@clients.first.client_orders.first.created_at) try this it will be true. so the problem is in the === statement and has nothing to do with join
– wasipeer
Jan 3 at 6:56
I tried that, and it still came out false: [78] pry(#<AccountManagementsController>)> time_range.include?(@clients.first.client_orders.first.created_at) D, [2019-01-03T07:09:00.695526 #1] DEBUG -- : CACHE ClientOrder Load (0.0ms) SELECT "client_orders".* FROM "client_orders" WHERE "client_orders"."client_id" = $1 ORDER BY "client_orders"."id" ASC LIMIT $2 [["client_id", 3], ["LIMIT", 1]] D, [2019-01-03T07:09:00.696902 #1] DEBUG -- : ↳ (pry):46 => false
– Jason Shultz
Jan 3 at 7:09
another issue is in time_range = (30.days.ago - 1.day)..Time.now.midnight. try this
– wasipeer
Jan 3 at 7:12