On Wednesday, November 21, 2012 10:56:58 AM UTC, Ruby-Forum.com User wrote:
>
>
> Instead of writing a simple SQL request, you write a complicated set of 
> methods' invocations (with options...). 
>
> The resulting code is not easy to read. You think : I should write an 
> easy to read SQL request! 
>
>
Not sure I buy that.

I'd far rather write

Garment.join(:brand).where(:brands => {:published => true}, :category_id => 
jumpers)

than

find_by_sql(['select * from garments
inner join brands on garments.brand_id = brands.id
where brands.published = true AND category_id = ?', jumpers)

And it only gets better as the query grows in complexity - building up 
strings is a pain in the arse, for example


Garment.where(criteria.reject {|k,v| v.blank?)

as opposed

to

criteria.collect |name, value|
  "#{connection.quote name} = #{connection.quote value}"
end.join( ' AND ')

 

> Some says : yes, but by using the database abstraction, you can change 
> you database easily (ex : from MySql to SQLServer)! 
>
> OK, but... Did you ever change your database ? 
>
> If you really need to migrate from MySql to SQLServer, then it means 
> that you have a *deep* problem. You may need to restructure your 
> database... 
>
> It's certainly true that changing database will always be a big effort, 
even if you write 0 lines of sql in your rails app.
 

> And what about "migrations" ? 
>
> Migrations keep track of structure's changes. OK, but why don't you just 
> keep your database's schema under SVN (or Git) ? 
>
>  
just storing the schema doesn't always tell you how to apply changes to 
that schema 

 

> Migrations can be used to change the database's content. OK, but 
> everything is not reversible. And, by the way, you should always work on 
> the testing environment. 
>
> So, my question is : 
>
> Do you really use all the Rails' tools to manage your database ? 
>
>  
I do
 

> Can you use Rails without Active Record ? 
>
>  
Absolutely. You could use data mapper for example or not use a SQL database 
at all. I've built apps that only used couchdb or mongo or that didn't have 
a persistence layer of their own at all.

Fred
 

> Thanks, 
>
> Denis 
>
> -- 
> 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@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/PrvbLyRglMYJ.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to