You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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=#Comment:0x00000002562028)(comments=#Comment:0x00000002561d30)))
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 => "[email protected]"
#)
#
#User.create(
# :name => "UserB",
# :email => "[email protected]"
#)
####################################################
@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
The text was updated successfully, but these errors were encountered:
what I do usually do is using
def self.repository_name
:ldap
end
to bind a model to a repository (but loosing the repository(:asdas) do ... end semantic).
but when I compare your example with the spec then the association is the other way around. looks like a bug. will look into it . . .
Kristian
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=#Comment:0x00000002562028)(comments=#Comment:0x00000002561d30)))
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
The text was updated successfully, but these errors were encountered: