Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL --> LDAP joins #9

Open
krissi opened this issue Oct 11, 2011 · 1 comment
Open

SQL --> LDAP joins #9

krissi opened this issue Oct 11, 2011 · 1 comment

Comments

@krissi
Copy link
Contributor

krissi commented Oct 11, 2011

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

#!/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
@mkristian
Copy link
Owner

have a look at
https://github.com/mkristian/dm-ldap-adapter/blob/master/spec/multi_repository_spec.rb
maybe that helps.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants