I am trying to get a very simple statement working.
Node.where("nodeid = ?", nstart).select('id')
Results in
Parameters: {"utf8"=>"✓", "authenticity_token"=>"WpSpzLzaFUx8QgFbwEfygQUkkqvbUgZl8Hh0UxJvT8E=", "edge"=>{"kind"=>"IsA", "start_id"=>"blabla", "end_id"=>"bliblib", "property1"=>"bloblbo"}, "commit"=>"Create Edge"}
(0.0ms) begin transaction
Node Load (0.1ms) SELECT "nodes".* FROM "nodes" WHERE "nodes"."id" = ? LIMIT 1 [["id", 0]]
CACHE (0.0ms) SELECT "nodes".* FROM "nodes" WHERE "nodes"."id" = ? LIMIT 1 [["id", 0]]
(0.0ms) rollback transaction
It should be just a ´select nodes.id from nodes where nodeid = blabla´ The limit doesn't matter.
However if I add .first.
Node.where("nodeid = ?", nstart).select('id').first
I get
Parameters: {"utf8"=>"✓", "authenticity_token"=>"WpSpzLzaFUx8QgFbwEfygQUkkqvbUgZl8Hh0UxJvT8E=", "edge"=>{"kind"=>"IsA", "start_id"=>"blabla", "end_id"=>"bliblib", "property1"=>"bloblbo"}, "commit"=>"Create Edge"}
Node Load (0.1ms) SELECT "nodes"."id" FROM "nodes" WHERE (nodeid = 'blabla') ORDER BY "nodes"."id" ASC LIMIT 1
Node Load (0.1ms) SELECT "nodes"."id" FROM "nodes" WHERE (nodeid = 'bliblib') ORDER BY "nodes"."id" ASC LIMIT 1
(0.0ms) begin transaction
Node Load (0.1ms) SELECT "nodes".* FROM "nodes" WHERE "nodes"."id" = ? LIMIT 1 [["id", 0]]
CACHE (0.0ms) SELECT "nodes".* FROM "nodes" WHERE "nodes"."id" = ? LIMIT 1 [["id", 0]]
(0.1ms) rollback transaction
The first select now is what it should be but the follow up is again like before and seems to determine the eventual return value (because it doesn't work either). I just want the id when I only know the nodeid which basically is the name of the node.
What is going on in Rails here?
Node.where("nodeid = ?", nstart).select('id')