{"id":525,"date":"2007-04-22T00:57:17","date_gmt":"2007-04-22T05:57:17","guid":{"rendered":"http:\/\/www.bytebot.net\/blog\/archives\/2007\/04\/22\/activerecord"},"modified":"2007-04-22T00:57:18","modified_gmt":"2007-04-22T05:57:18","slug":"activerecord","status":"publish","type":"post","link":"http:\/\/www.bytebot.net\/blog\/archives\/2007\/04\/22\/activerecord","title":{"rendered":"ActiveRecord"},"content":{"rendered":"<p>ActiveRecord, by <a href=\"http:\/\/anarchogeek.com\/\">Rabble<\/a>.<\/p>\n<ul>\n<li>Rails <a href=\"http:\/\/wiki.rubyonrails.com\/rails\/pages\/ActiveRecord\">ActiveRecord<\/a> is mostly database agnostic. <\/li>\n<li>Good subset of the SQL standard is supported, so you can migrate very easily (this is what OS X Leopard will do &#8211; develop using sqlite on your workstation, then migrate to mysql on the server).<\/li>\n<li>Integer primary keys, and classname_id foreign keys. Single table inheritance is what really works well. <\/li>\n<li>What ActiveRecord doesn&#8217;t like: <\/li>\n<\/ul>\n<ol>\n<li>views<\/li>\n<li>stored procedures<\/li>\n<li>FK constraints<\/li>\n<li>cascading commits<\/li>\n<li>split\/clustered DBs<\/li>\n<li>enums<\/li>\n<\/ol>\n<ul>\n<li>Complexity is best located in the code, not in the database, according to the Rails developers.<\/li>\n<li>Avoid SQL injection with find. Use an array or let it do the quoting for you. By itself, it allows you to do stupid things &#8211; so avoid cross site scripting, etc.<\/li>\n<li>Joins are very rarely used, you use ActiveRecord relationships.<\/li>\n<li>Some associations:<\/li>\n<\/ul>\n<ol>\n<li>has_one &#8211; when the FK is in the OTHER table<\/li>\n<li>belongs_to &#8211; when the FK is in THIS table<\/li>\n<li>has_many<\/li>\n<li>has_and_belongs_to_many<\/li>\n<\/ol>\n<ul>\n<li>DBAs like FK constraints, but the Rails way is to really just use validations.<\/li>\n<li>ActiveRecord returns enumarable objects, which look like arrays<\/li>\n<li>ActiveRecord also allows for output formats &#8211; like to_yaml, to_xml, to_json. So your database records can become XML pretty easily.<\/li>\n<li>find_by_sql &#8211; use it when you&#8217;re finding ActiveRecord isn&#8217;t suitable for you, i.e. you&#8217;re doing something that is not very standard.<\/li>\n<\/ul>\n<p>Rabble also gave us an anecdote from his Odeo days. They thought that grabbing feeds should be done in parallel. Which is when they used RubyThreads. And suddenly, they were getting some horrendous database problems, duplicate records and so on. Moral of the story: RubyThreads and ActiveRecord don&#8217;t mix. A member of the audience mentioned that using find_by_sql consumed about 1MB of memory in his application, however, using ActiveRecord to do the same thing was costing about 20MB per thread.<\/p>\n<p>Technorati Tags: <a class=\"performancingtags\" href=\"http:\/\/technorati.com\/tag\/ruby\" rel=\"tag\">ruby<\/a>, <a class=\"performancingtags\" href=\"http:\/\/technorati.com\/tag\/svrc2007\" rel=\"tag\">svrc2007<\/a>, <a class=\"performancingtags\" href=\"http:\/\/technorati.com\/tag\/database\" rel=\"tag\">database<\/a>, <a class=\"performancingtags\" href=\"http:\/\/technorati.com\/tag\/sql\" rel=\"tag\">sql<\/a>, <a class=\"performancingtags\" href=\"http:\/\/technorati.com\/tag\/mysql\" rel=\"tag\">mysql<\/a>, <a class=\"performancingtags\" href=\"http:\/\/technorati.com\/tag\/ActiveRecord\" rel=\"tag\">ActiveRecord<\/a><\/p>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-email\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-email sd-button share-icon\" href=\"mailto:?subject=%5BShared%20Post%5D%20ActiveRecord&body=http%3A%2F%2Fwww.bytebot.net%2Fblog%2Farchives%2F2007%2F04%2F22%2Factiverecord&share=email\" target=\"_blank\" title=\"Click to email a link to a friend\" data-email-share-error-title=\"Do you have email set up?\" data-email-share-error-text=\"If you&#039;re having problems sharing via email, you might not have email set up for your browser. You may need to create a new email yourself.\" data-email-share-nonce=\"932d76c95d\" data-email-share-track-url=\"http:\/\/www.bytebot.net\/blog\/archives\/2007\/04\/22\/activerecord?share=email\"><span>Email<\/span><\/a><\/li><li class=\"share-facebook\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-facebook-525\" class=\"share-facebook sd-button share-icon\" href=\"http:\/\/www.bytebot.net\/blog\/archives\/2007\/04\/22\/activerecord?share=facebook\" target=\"_blank\" title=\"Click to share on Facebook\" ><span>Facebook<\/span><\/a><\/li><li class=\"share-linkedin\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-linkedin-525\" class=\"share-linkedin sd-button share-icon\" href=\"http:\/\/www.bytebot.net\/blog\/archives\/2007\/04\/22\/activerecord?share=linkedin\" target=\"_blank\" title=\"Click to share on LinkedIn\" ><span>LinkedIn<\/span><\/a><\/li><li class=\"share-twitter\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-twitter-525\" class=\"share-twitter sd-button share-icon\" href=\"http:\/\/www.bytebot.net\/blog\/archives\/2007\/04\/22\/activerecord?share=twitter\" target=\"_blank\" title=\"Click to share on Twitter\" ><span>Twitter<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>ActiveRecord, by Rabble. Rails ActiveRecord is mostly database agnostic. Good subset of the SQL standard is supported, so you can migrate very easily (this is what OS X Leopard will do &#8211; develop using sqlite on your workstation, then migrate to mysql on the server). Integer primary keys, and classname_id foreign keys. Single table inheritance [&hellip;]<\/p>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-email\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-email sd-button share-icon\" href=\"mailto:?subject=%5BShared%20Post%5D%20ActiveRecord&body=http%3A%2F%2Fwww.bytebot.net%2Fblog%2Farchives%2F2007%2F04%2F22%2Factiverecord&share=email\" target=\"_blank\" title=\"Click to email a link to a friend\" data-email-share-error-title=\"Do you have email set up?\" data-email-share-error-text=\"If you&#039;re having problems sharing via email, you might not have email set up for your browser. You may need to create a new email yourself.\" data-email-share-nonce=\"932d76c95d\" data-email-share-track-url=\"http:\/\/www.bytebot.net\/blog\/archives\/2007\/04\/22\/activerecord?share=email\"><span>Email<\/span><\/a><\/li><li class=\"share-facebook\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-facebook-525\" class=\"share-facebook sd-button share-icon\" href=\"http:\/\/www.bytebot.net\/blog\/archives\/2007\/04\/22\/activerecord?share=facebook\" target=\"_blank\" title=\"Click to share on Facebook\" ><span>Facebook<\/span><\/a><\/li><li class=\"share-linkedin\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-linkedin-525\" class=\"share-linkedin sd-button share-icon\" href=\"http:\/\/www.bytebot.net\/blog\/archives\/2007\/04\/22\/activerecord?share=linkedin\" target=\"_blank\" title=\"Click to share on LinkedIn\" ><span>LinkedIn<\/span><\/a><\/li><li class=\"share-twitter\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-twitter-525\" class=\"share-twitter sd-button share-icon\" href=\"http:\/\/www.bytebot.net\/blog\/archives\/2007\/04\/22\/activerecord?share=twitter\" target=\"_blank\" title=\"Click to share on Twitter\" ><span>Twitter<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_options":[]},"categories":[1],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4vJD-8t","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":528,"url":"http:\/\/www.bytebot.net\/blog\/archives\/2007\/04\/23\/scaling-twitter-is-twitter-is-udp-or-tcp-its-definitely-udp","url_meta":{"origin":525,"position":0},"title":"Scaling Twitter: &#8220;Is Twitter is UDP or TCP? Its definitely UDP.&#8221;","date":"23\/4\/2007","format":false,"excerpt":"Presented by Blaine Cook, a developer from Odeo, now probably CTO of Twitter (Obvious Corp spawed, I think). There's a video and slides (yes, you need evil Flash so I haven't viewed it myself). Then there are my notes... possibly with some thoughts attached to them. No, they're not organized,\u2026","rel":"","context":"In &quot;MySQL&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":515,"url":"http:\/\/www.bytebot.net\/blog\/archives\/2007\/04\/17\/second-annual-silicon-valley-ruby-conference","url_meta":{"origin":525,"position":1},"title":"Second Annual Silicon Valley Ruby Conference","date":"17\/4\/2007","format":false,"excerpt":"In addition to the MySQL Conference & Expo 2007, which I just registered for (yes, its not too late, register now!), I also registered for the Second Annual Silicon Valley Ruby Conference. Its at The Tech Museum in San Jose (I honestly have no idea where that is from the\u2026","rel":"","context":"In &quot;General&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":761,"url":"http:\/\/www.bytebot.net\/blog\/archives\/2008\/03\/31\/hitchhackers-guide-to-the-mysql-conference-rubyruby-on-rails-edition","url_meta":{"origin":525,"position":2},"title":"Hitchhacker&#8217;s Guide to the MySQL Conference &#8211; Ruby\/Ruby on Rails Edition","date":"31\/3\/2008","format":false,"excerpt":"The Hitchhacker's Guide to the MySQL Conference Ruby\/Ruby on Rails Developer's Edition Following on from the excellent Hitchhacker's Guide to the MySQL Conference - PHP Edition by Jay Pipes, I'm doing one for the Ruby and Ruby on Rails developer in you. If you haven't registered yet, remember, I can\u2026","rel":"","context":"In &quot;MySQL&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2816,"url":"http:\/\/www.bytebot.net\/blog\/archives\/2013\/11\/11\/mariadb-10-0-5-storage-engines-check-the-linux-packages","url_meta":{"origin":525,"position":3},"title":"MariaDB 10.0.5 storage engines &#8211; check the Linux packages","date":"11\/11\/2013","format":false,"excerpt":"Today before Ivan's tutorial, he told me that in the 10.0.5 virtual machine images he created, he couldn't find the Cassandra storage engine. I told him it had to be installed separately, and this is true - you have to install some engines separately! When you do a yum install\u2026","rel":"","context":"In &quot;MariaDB&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1720,"url":"http:\/\/www.bytebot.net\/blog\/archives\/2010\/03\/07\/abusing-mysql-thoughts-on-nosql","url_meta":{"origin":525,"position":4},"title":"Abusing MySQL (&#038; thoughts on NoSQL)","date":"7\/3\/2010","format":false,"excerpt":"The NoSQL\/relational database debate has been going on for quite some time. MariaDB, like MySQL is relational. And if you read these series of blog posts, you'll realise that if you use MySQL correctly, you can achieve quite a lot. It all starts with Kellan Elliott-McCrea with his introductory post\u2026","rel":"","context":"In &quot;Databases&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1464,"url":"http:\/\/www.bytebot.net\/blog\/archives\/2009\/04\/22\/video-interview-with-microsofts-php-evangelist","url_meta":{"origin":525,"position":5},"title":"Video: Interview with Microsoft&#8217;s PHP Evangelist","date":"22\/4\/2009","format":false,"excerpt":"I caught up with Zach Skyles Owens, a PHP Evangelist at Microsoft. If you missed the embed, watch the video. I have some sparse notes below. I learned some new things: Microsoft spends time working with the PHP community They are porting applications to work with an SQL Server backend\u2026","rel":"","context":"In &quot;MySQL&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"amp_enabled":true,"_links":{"self":[{"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/posts\/525"}],"collection":[{"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/comments?post=525"}],"version-history":[{"count":0,"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/posts\/525\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/media?parent=525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/categories?post=525"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/tags?post=525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}