Created
September 28, 2009 16:17
-
-
Save phatmann/195538 to your computer and use it in GitHub Desktop.
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
require 'rubygems' | |
gem 'dm-core' | |
require 'dm-core' | |
DataMapper::Logger.new(STDOUT, :debug) | |
DataMapper.setup(:default, "mysql://localhost/YOUR_TEST_DB") | |
class CrawledPage | |
include DataMapper::Resource | |
property :id, Serial | |
belongs_to :crawling_run | |
end | |
class CrawlingRun | |
include DataMapper::Resource | |
property :id, Serial | |
belongs_to :board_account | |
has n, :crawled_pages | |
end | |
class Board | |
include DataMapper::Resource | |
property :id, Serial | |
end | |
class BoardAccount | |
include DataMapper::Resource | |
property :id, Serial | |
belongs_to :board | |
belongs_to :recruiter | |
has n, :crawling_runs | |
end | |
class Recruiter | |
include DataMapper::Resource | |
property :id, Serial | |
belongs_to :team | |
has n, :board_accounts | |
end | |
class Team | |
include DataMapper::Resource | |
property :id, Serial | |
end | |
puts "******** Create tables ********" | |
DataMapper.auto_migrate! | |
puts "\n\n" | |
puts "******** Create resources ********" | |
board = Board.create | |
team = Team.create | |
recruiter = Recruiter.create(:team => team) | |
board_account = BoardAccount.create(:board => board, :recruiter => recruiter) | |
crawling_run = CrawlingRun.create(:board_account => board_account) | |
crawled_page = CrawledPage.create(:crawling_run => crawling_run) | |
puts "\n\n" | |
puts "******** Query 1 works ********" | |
CrawledPage.first('crawling_run.board_account.board_id' => 1) | |
puts "\n\n" | |
puts "******** Query 2 works ********" | |
CrawledPage.first('crawling_run.board_account.board_id' => 1, 'crawling_run.board_account.recruiter_id' => 1) | |
puts "\n\n" | |
puts "******** Query 3 fails ********" | |
CrawledPage.first('crawling_run.board_account.board_id' => 1, 'crawling_run.board_account.recruiter.team_id' => 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment