HighDots Forums  

Which finder syntax would be preferred as far as being themost database agnostic?

Ruby On Rails Talk Ruby On Rails programming language mailing list


Discuss Which finder syntax would be preferred as far as being themost database agnostic? in the Ruby On Rails Talk forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Lee Smith
 
Posts: n/a

Default Which finder syntax would be preferred as far as being themost database agnostic? - 11-04-2009 , 11:39 PM






Which finder syntax is preferred? Or are they the same?

I'm developing on sqlite and I've posted the result of each
query...they kind of look the same but not really. Would this scale
to say, Mysql or Postgres? Thanks for any advice.

named_scope :disabled, rder => 'name', :conditions => { :disabled_at
=> !nil }
SELECT * FROM "groups" WHERE ("groups"."disabled_at" = 't') ORDER BY
name

or

named_scope :disabled, rder => 'name', :conditions => ['disabled_at
<> ?', nil]
SELECT * FROM "groups" WHERE (disabled_at <> NULL) ORDER BY name
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
  #2  
Old   
Tim Lowrimore
 
Posts: n/a

Default Re: Which finder syntax would be preferred as far as beingthe most database agnostic? - 11-05-2009 , 12:36 AM






I for one prefer the first syntax, since it eliminates SQL from the
ruby code, but that's just my preference.

Cheers,
Tim

On Nov 4, 10:39*pm, Lee Smith <autige... (AT) gmail (DOT) com> wrote:
Quote:
Which finder syntax is preferred? *Or are they the same?

I'm developing on sqlite and I've posted the result of each
query...they kind of look the same but not really. *Would this scale
to say, Mysql or Postgres? *Thanks for any advice.

named_scope :disabled, rder => 'name', :conditions => { :disabled_at
=> !nil }
SELECT * FROM "groups" WHERE ("groups"."disabled_at" = 't') ORDER BY
name

or

named_scope :disabled, rder => 'name', :conditions => ['disabled_at
?', nil]
SELECT * FROM "groups" WHERE (disabled_at <> NULL) ORDER BY name
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
  #3  
Old   
Marnen Laibow-Koser
 
Posts: n/a

Default Re: Which finder syntax would be preferred as far as being t - 11-05-2009 , 08:19 AM



Lee Smith wrote:
Quote:
Which finder syntax is preferred? Or are they the same?

I'm developing on sqlite and I've posted the result of each
query...they kind of look the same but not really. Would this scale
to say, Mysql or Postgres? Thanks for any advice.

named_scope :disabled, rder => 'name', :conditions => { :disabled_at
=> !nil }
SELECT * FROM "groups" WHERE ("groups"."disabled_at" = 't') ORDER BY
name

or

named_scope :disabled, rder => 'name', :conditions => ['disabled_at
?', nil]
SELECT * FROM "groups" WHERE (disabled_at <> NULL) ORDER BY name
Use the first syntax -- the second one is incorrect. I don't know if
this is true in SQLite, but in the other DBs, NULL = NULL returns NULL,
so your <> NULL construct will return TRUE in all cases, and so it is
pointless. In the first case, Rails automatically generates the proper
syntax.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen (AT) marnen (DOT) org
--
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
  #4  
Old   
Marnen Laibow-Koser
 
Posts: n/a

Default Re: Which finder syntax would be preferred as far as being t - 11-05-2009 , 08:22 AM



Marnen Laibow-Koser wrote:
Quote:
Lee Smith wrote:
Which finder syntax is preferred? Or are they the same?

I'm developing on sqlite and I've posted the result of each
query...they kind of look the same but not really. Would this scale
to say, Mysql or Postgres? Thanks for any advice.

named_scope :disabled, rder => 'name', :conditions => { :disabled_at
=> !nil }
SELECT * FROM "groups" WHERE ("groups"."disabled_at" = 't') ORDER BY
name

or

named_scope :disabled, rder => 'name', :conditions => ['disabled_at
?', nil]
SELECT * FROM "groups" WHERE (disabled_at <> NULL) ORDER BY name

Use the first syntax -- the second one is incorrect. I don't know if
this is true in SQLite, but in the other DBs, NULL = NULL returns NULL,
so your <> NULL construct will return TRUE in all cases, and so it is
pointless. In the first case, Rails automatically generates the proper
syntax.
On second thought, *both* are incorrect. Use :conditions =>
'disabled_at is not null'.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen (AT) marnen (DOT) org
Quote:
Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen (AT) marnen (DOT) org
--
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
  #5  
Old   
Frederick Cheung
 
Posts: n/a

Default Re: Which finder syntax would be preferred as far as being t - 11-05-2009 , 08:28 AM



On Nov 5, 1:19*pm, Marnen Laibow-Koser <rails-mailing-l...@andreas-
s.net> wrote:

Quote:

named_scope :disabled, rder => 'name', :conditions => ['disabled_at
?', nil]
SELECT * FROM "groups" WHERE (disabled_at <> NULL) ORDER BY name

Use the first syntax -- the second one is incorrect. *I don't know if
this is true in SQLite, but in the other DBs, NULL = NULL returns NULL,
so your <> NULL construct will return TRUE in all cases, and so it is
pointless. *In the first case, Rails automatically generates the proper
syntax.
Actually NULL <> NULL is also NULL. Hooray for 3 way logic. (doesn't
mean the OP's would work though). In general I tend to use the hash
form of conditions when possible, but that's not always the case.

Fred

Quote:
Best,
--
Marnen Laibow-Koserhttp://www.marnen.org
mar... (AT) marnen (DOT) org
--
Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.