mkristian/dm-ldap-adapter — Issue #9: SQL --> LDAP joins
Author: krissi
Created: 2011-10-11 13:58:41+00:00
State: open

Hi,

I tried to do some joins between sqlite and ldap. Unfortunately there seems to be a problem when building the LDAP filter. Please see the attached Script.

The line `puts "#{c.user.name} (#{c.user.email}):"` does not return the correct data because the search filter is built wrong:
DEBUG -- Ldap::Conditions2Filter: (Ldap::Conditions2Filter) search filter: ((|(comments=#)(comments=#)))

`class Comment` is not in LDAP, but in SQLite in the default repository. If I uncomment the disabled blocks this way of cross repository joining works as expected.

Thanks,
Christian

````
#!/usr/bin/env ruby

require 'rubygems'
require 'datamapper'
require 'adapters/ldap_adapter'
require 'slf4r/logger'
require 'slf4r/ruby_logger'
require 'ldap_resource'

DataMapper::Logger.new($stderr, :debug)

DataMapper.setup(:default, 'sqlite::memory:')
#DataMapper.setup(:ldap, 'sqlite::memory:')

DataMapper.setup(:ldap, {
:adapter	=> 'ldap',
:facade	=> :ruby_ldap,
:host	=> 'xxx.intranet.ifu-hh.de',
:port	=> 636,
:base	=> 'o=ifu',
:bind_name	=> "uid=user,ou=People,o=xxx",
:password	=> "pass"
})

class Post
include DataMapper::Resource

property :id,	Serial
property :title,	String
property :body,	Text
property :created_at,	DateTime

has n, :comments
end

class Comment
include DataMapper::Resource

property :id,	Serial
property :body,	Text

belongs_to :post
belongs_to :user, :repository => repository(:ldap)
end

#class User
#	include DataMapper::Resource
#
#	def self.default_repository_name
#	:ldap
#	end
#
#	property :id,	Serial
#	property :name,	String
#	property :email,	String
#
#	has n, :comments
#end

class User
include DataMapper::Resource

def self.default_repository_name
:ldap
end

property :id,	Serial, :field => "uidNumber"
property :name,	String, :field => "displayName", :unique_index => true
property :email,	String, :field => "MailAddress"

dn_prefix { |user| "uid=#{user.login}"}
treebase "ou=People"

has n, :comments, :model => 'Comment', :repository => repository(:default)
end

DataMapper.finalize
DataMapper.auto_migrate!

#User.create(
#	:name	=> "User A",
#	:email	=> "UserA@example.com"
#)
#
#User.create(
#	:name	=> "UserB",
#	:email	=> "UserB@example.com"
#)

####################################################

@u_a = User.first(:name	=> "UserA")
@u_b = User.first(:name	=> "UserB")

@post = Post.create(
:title	=> "My first DataMapper post",
:body	=> "A lot of text ...",
:created_at	=> Time.now
)

@post.comments << Comment.new(
:body	=> "Testtesttest!",
:user	=> @u_a
)

@post.comments << Comment.new(
:body	=> "Yeah!",
:user	=> @u_b
)
@post.comments.save

# ===================================================

Post.each do |p|
puts p.title
puts p.title.gsub(/./, '=')
puts
puts p.body
puts
puts "Comments (#{p.comments.count}):"
p.comments.each do |c|
puts "#{c.user.name} (#{c.user.email}):"
puts " #{c.body}"
puts
end
end
````