This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Join Table Columns (2.3ms) SHOW FIELDS FROM `foos_bars` | |
Resident Load (18.7ms) SELECT * FROM `bars` INNER JOIN `foos_bars` ON `bars`.id = `foos_bars`.bar_id WHERE (`foos_bars`.foo_id = 1327 ) | |
SQL (0.1ms) BEGIN | |
SQL (51.2ms) DELETE FROM `foos_bars` WHERE foo_id = 1327 AND bar_id in (117261,117262,117263, . . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@foo.connection.execute("delete from foos_bars where foo_id = #{@foo.id}")} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo < ActiveRecord::Base | |
has_and_belongs_to_many :bars | |
end | |
class Bar < ActiveRecord::Base | |
has_and_belongs_to_many :foos | |
end | |
@foo = Foo.create | |
@bars = Bar.find_all_by_some_attribute(:a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Join Table Columns (2.3ms) SHOW FIELDS FROM `foos_bars` | |
Bar Load (18.7ms) SELECT * FROM `bars` INNER JOIN `foos_bars` ON `bars`.id = `foos_bars`.bar_id WHERE (`foos_bars`.foo_id = 1327 ) | |
SQL (0.1ms) BEGIN | |
SQL (51.2ms) DELETE FROM `foos_bars` WHERE foo_id = 1327 AND bar_id in (117261,117262,117263, . . | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#try this data set: | |
ARR = [[1, "red"], [1, "green"], | |
[2, "red"], | |
[3, "yellow"], | |
[4, "red"], [4, "green"], [4, "yellow"], | |
[5, "green"], [5, "red"], | |
[6, "black"], | |
[7, "foo"], | |
[8, "bar"], | |
[9, "baz"], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FB.init({ | |
appId : 'YOUR_APP_ID', | |
status : true, // check login status | |
cookie : true, // enable cookies to allow the server to access the session | |
xfbml : true // parse XFBML | |
}); | |
FB.getLoginStatus(function(response) { | |
if (response.session) { | |
// logged in and connected user, someone you know |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def history(num=100) | |
h = Readline::HISTORY.to_a | |
start = [0,h.size-num-1].max | |
h.zip((0..h.size).to_a)[start...h.size].each do |e,i| | |
puts " #{(i).to_s.rjust(4)} #{e}" | |
end;nil | |
end | |
>> history(7) | |
483 def history(num=100) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#models/user.rb | |
def user_city | |
read_attribute(:user_city) || address && address.city || "" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#models/user.rb | |
class User < ActiveRecord::Base | |
has_one :address | |
named_scope :with_city_info, | |
:joins=>:address, | |
:select="users.*, addresses.city as user_city" | |
end | |
#models/address.rb | |
class Address < ActiveRecord::Base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#models/user.rb | |
named_scope :with_city_info, | |
:joins=>:address, | |
:select="users.*, addresses.city as user_city" | |
#controllers/users_controller.b | |
def locations | |
@users = User.with_city_info | |
end |