Find.collect problem

Hi all.

I am trying to populate a dropdown based on two values.

def self.clientref( reference )
@bugclientrefs = self.find_all([“bug_id = ?”, reference]).collect {|b|
[ b.client_id.strip << " - " << b.client_ref.strip ]}
end

This works fine. However this returns the reference to the client. I
want the full name using this function.

class Bugclient < ActiveRecord::Base
set_primary_key “bc_ref”

def self.fullname( reference )
result = Bugclient.find(reference.strip)
result.bc_name
end
end

However I am not sure how to combine the two so that the client full
name is collected instead of the reference.

I have tried the simpleton approach of

@bugclientrefs = self.find_all([“bug_id = ?”, reference]).collect {|b|
[ Bugclient.fullname(b.client_id.strip) << " - " << b.client_ref.strip
]}

But that just returns errors

Does anyone know how to combine the two?

Thanks

Jeff

On Jan 27, 2006, at 8:19 AM, Jeff J. wrote:

This works fine. However this returns the reference to the client. I

But that just returns errors

Does anyone know how to combine the two?

It looks like you’re using a class method when you actually want a
regular instance method:

class Bugclient < ActiveRecord::Base
set_primary_key “bc_ref”

def fullname
bc_name
end
end

In fact, you don’t even need to write that method if you just refer
to bc_name directly (assuming bc_name is a column in the bugclients
table):

def self.clientref( reference )
@bugclientrefs = self.find_all([“bug_id = ?”, reference]).collect
{|b| [ b.bc_name.strip << " - " << b.client_ref.strip ]}
end

Duane J.
(canadaduane)
http://blog.inquirylabs.com/

Duane J. wrote:

On Jan 27, 2006, at 8:19 AM, Jeff J. wrote:

This works fine. However this returns the reference to the client. I

But that just returns errors

Does anyone know how to combine the two?

It looks like you’re using a class method when you actually want a
regular instance method:

class Bugclient < ActiveRecord::Base
set_primary_key “bc_ref”

def fullname
bc_name
end
end

In fact, you don’t even need to write that method if you just refer
to bc_name directly (assuming bc_name is a column in the bugclients
table):

def self.clientref( reference )
@bugclientrefs = self.find_all([“bug_id = ?”, reference]).collect
{|b| [ b.bc_name.strip << " - " << b.client_ref.strip ]}
end

Duane J.
(canadaduane)
http://blog.inquirylabs.com/

Whoops, I am not following you 100% here (This is what I get for copoy /
pasting / mangling a function without fully understanding it :slight_smile:

I don’t think I gave you the full story either. def self.clientref(
reference ) is in another class which doesn’t hold the full client name.
I’ll give you the full source.


class Bugclientref < ActiveRecord::Base
set_primary_key “bug_id”

def self.clientref( reference )
@bugclientrefs = self.find_all([“bug_id = ?”, reference]).collect
{|b| [ b.bc_name.strip << " - " << b.client_ref.strip ]}
end
end


class Bugclient < ActiveRecord::Base
set_primary_key “bc_ref”

def self.fullname( reference )
result = Bugclient.find(reference.strip)
result.bc_name

end
end


So the collect SHOULD be trying to get the fullname from Bugclient based
on the reference in Bugclientref and adding it to the Reference from
Bugclientref.

Does this make sense? It hurts my head thinking about it. I want to kill
the guy who came up with this schema.

Don’t you love newbies? :slight_smile:

Thanks

Jeff

On Jan 27, 2006, at 9:28 AM, Jeff J. wrote:

It looks like you’re using a class method when you actually want a
end

reference ) is in another class which doesn’t hold the full client
{|b| [ b.bc_name.strip << " - " << b.client_ref.strip ]}
result.bc_name

Does this make sense? It hurts my head thinking about it. I want to
kill
the guy who came up with this schema.

Don’t you love newbies? :slight_smile:

Thanks

Jeff

What kind of errors are you getting? Is it possible that some of the
"b.client_id.strip"s that you’re passing in don’t exist in the
Bugclient table? Maybe you’re doing it right, but the state of the
database integrity just isn’t what you’re expecting.

Duane J.
(canadaduane)
http://blog.inquirylabs.com/

Duane J. wrote:

On Jan 27, 2006, at 9:28 AM, Jeff J. wrote:

It looks like you’re using a class method when you actually want a
end

reference ) is in another class which doesn’t hold the full client
{|b| [ b.bc_name.strip << " - " << b.client_ref.strip ]}
result.bc_name

Does this make sense? It hurts my head thinking about it. I want to
kill
the guy who came up with this schema.

Don’t you love newbies? :slight_smile:

Thanks

Jeff

What kind of errors are you getting? Is it possible that some of the
"b.client_id.strip"s that you’re passing in don’t exist in the
Bugclient table? Maybe you’re doing it right, but the state of the
database integrity just isn’t what you’re expecting.

Duane J.
(canadaduane)
http://blog.inquirylabs.com/

Since I am not at work until Monday now I will have to get back to you.
Thanks for all the help!

Jeff