Skip to content

Instantly share code, notes, and snippets.

@ku1ik
Created February 3, 2010 16:47
Show Gist options
  • Save ku1ik/293759 to your computer and use it in GitHub Desktop.
Save ku1ik/293759 to your computer and use it in GitHub Desktop.
class Blocking
include DataMapper::Resource
property :task_id, Integer, :required => true, :index => true, :key => true
property :blocker_id, Integer, :required => true, :index => true, :key => true
belongs_to :task
belongs_to :blocker, :model => Task
end
Task.first.blockers
DataObjects::SQLError: Not unique table/alias: 'tasks' (code: 1066, sql state: 42000, query: SELECT `tasks`.`id`, `tasks`.`title` FROM `tasks` INNER JOIN `blockings` ON `tasks`.`id` = `blockings`.`blocker_id` INNER JOIN `tasks` ON `blockings`.`task_id` = `tasks`.`id` WHERE `blockings`.`task_id` = 1 GROUP BY `tasks`.`id`, `tasks`.`title` ORDER BY `tasks`.`id`
class Task
include DataMapper::Resource
property :id, Serial
property :title, :required => true, :length => 256
has n, :blockings
has n, :blockers, :through => :blockings, :model => Task
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment