HOWTO: Combine fields from 2 two tables in 1 object

Hi all,

For a dropdownlist (showing "Company - FirstName Lastname’) I want to
fill an
object @project_contacts with “Name” from table Companies and
“Firstname” and
“Lastname” from table contacts. Any idea?

Regards,

Gerard.


“Who cares if it doesn’t do anything? It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process …”

My $Grtz =~ Gerard;
~
:wq!

Hi all,

Watery eyes … Nevermind the previous. I don’t see that working for me.

This is what I want. I create a new project, and want to copy some
contact and
company info into a project table.

I don’t see a link (selected via a view) between to completely seperate
tables. Let alone get data from one to the other.

Please help?

Gerard.

On Thursday 05 January 2006 13:49, Gerard tried to type something like:

Hi all,

For a dropdownlist (showing "Company - FirstName Lastname’) I want to fill
an object @project_contacts with “Name” from table Companies and
“Firstname” and “Lastname” from table contacts. Any idea?

Regards,

Gerard.


“Who cares if it doesn’t do anything? It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process …”

My $Grtz =~ Gerard;
~
:wq!

assuming certain relationships between projects/contacts/companies

projects (hm) <–> (bt) contacts (bt) <–> (hm) companies

controller:

@project.find(1)
@project_contacts = @project.contacts.collect { |c| [ c.company.name + "

  • "
  • c.first_name + " " + c.last_name, c.id ] }

@project_contacts => [ [ “Acme -Bob S.”, 1], ["MegaCorp - Jane

Doe",
2], … ]

view:

<%= select(“project”, “contact_id”, @project_contacts ) %>

Chris,

Hurtfully I must state being a newbie can slow things down … :slight_smile:

Cudo’s on your solution. It hits the nail on the head. Looking at your
solution … .would it be wise to buy the pragmatic ruby book. Or do I
just
need to keep going knowing I’ll get better?

Anyway …

projects (hm) ↔ (bt) contacts (bt) ↔ (hm) companies
Very close. This is true:(bt) contacts (bt) ↔ (hm) companies

And there is: projects (ho) ↔ (bt) project_contacts

The reason is that when a contact resigns (is deleted) I still want to
be able
to view closed projects. Herewith avoiding the (for me) infamous ‘nil’
errors.

Since there’s no relationship between projects & project_contacts on one
side
and contacts on the other. Looks like I need to do a second object fill
when
saving the new project. I can then use the ‘"c.id’ that comes back from
@project_contacts and use that id to gather the info for storing it. Or
is
that info still avalaible in @project.contacts.collect ?

Thanx so much for helping me out.

Gerard

:wq!


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


“Who cares if it doesn’t do anything? It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process …”

My $Grtz =~ Gerard;
~
:wq!

Hi,

We have experienced some problems with
ActiveRecord::Base class of Ruby-Rails. We are
building a web-application based on the Ruby-rails
framework and the web-application needs to access to
difference databases, so we do not pre-define our
database accesses in the database.yml file. In fact,
we are using the
ActiveRecord::Base.establish_connection() to connect
to our database, the function works perfectly.
However, while we try to disconnect our database
connection with
ActiveRecord::Base.remove_connection(), we find out
that the connection is not closed (the function seems
not to be working perfectly) and we are still
connected to the database and able to access to the
tables.

Can you please tell us, is there something we did
wrong? or it is a known problem?
and what should we do to disconnect a database
connection ?

The using version ruby-rails are :
Rails 0.14.2 and ruby 1.8.3 (2005-09-21)
[x86_64-linux]
We are running on Linux KDE 3.4, and our database
engine is postgresql

The following is a code example:
####################################################################################

class GenTableAs < ActiveRecord::Base
end

class GentestController < ApplicationController

def index
	GenTableAs.establish_connection(:adapter =>

“postgresql”,
:host => “1.2.3.4”,
:port => 5432,
:database => “gendb”,
:username => “dbuser”,
:password => “dbuser”)
@connected1 = GenTableAs.connection()
@removedConnection = GenTableAs.remove_connection()

	@connected2 = GenTableAs.connection() # should be

nil here
obj1 = GenTableAs.new
obj1[“colaa”] = 100
obj1[“colab”] = “100”
obj1.save # should have raised exception or error
here
end
end
####################################################################################
the output of index

@connected1:

#<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter:0x2aaaac138930
@runtime=0.0189187526702881,
@connection=#PGconn:0x2aaaac138980,
@logger=#<Logger:0x2aaaac2e7fd8
@default_formatter=#<Logger::Formatter:0x2aaaac2e7dd0
@datetime_format=nil>, @progname=nil,
@logdev=#<Logger::LogDevice:0x2aaaac2e7ce0
@shift_size=1048576, @shift_age=0,
@filename=“./log/development.log”,
@mutex=#<Logger::LogDevice::LogDeviceMutex:0x2aaaac2e7c90
@mon_waiting_queue=[], @mon_entering_queue=[],
@mon_count=0, @mon_owner=nil>,
@dev=#<File:./log/development.log>>, @level=0,
@formatter=nil>>

removed connection:

:password: dbuser
:database: gendb
:host: 1.2.3.4
:port: 5432
:adapter: postgresql
:username: dbuser

@connected2:

#<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter:0x2aaaac138930
@runtime=0.0189187526702881,
@connection=#PGconn:0x2aaaac138980,
@logger=#<Logger:0x2aaaac2e7fd8
@default_formatter=#<Logger::Formatter:0x2aaaac2e7dd0
@datetime_format=nil>, @progname=nil,
@logdev=#<Logger::LogDevice:0x2aaaac2e7ce0
@shift_size=1048576, @shift_age=0,
@filename=“./log/development.log”,
@mutex=#<Logger::LogDevice::LogDeviceMutex:0x2aaaac2e7c90
@mon_waiting_queue=[], @mon_entering_queue=[],
@mon_count=0, @mon_owner=nil>,
@dev=#<File:./log/development.log>>, @level=0,
@formatter=nil>>

Thanks you very much !!!

Saiho


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around

Hi,

I wish to know where and when exactly the rails
connects to a database when we create a subclass of
ActiveReocrd::base ? And How ActiveRecord::base work
exactly?

I took a look on the classes ConnectionSpecification,
PostgreSQLAdapter(we are using Postgresql) and
AbstractAdapter. I cannot figure out function calling
stack. Can someone can tell me how the all these
functions is called?

As I understand the connections is stored in the
@@defined_connections od the class
ConnectionSpecification. And when we “remove” the
connection, the function “remove connection” only
remove the connection from the variable
@@defined_connections, but it does not “disconnect”
the connection between rails and the database, So I
wonder when the rails connects to the database, and
when rails decides to disconnect, and how it is done?

Thanks you very much

Saiho


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around

Chris,

Having chewed on the line bewol some more

@project_contacts = @contacts_list.collect { |c| [ c.name + " - " +
c.firstname + " " + c.lastname, c.id ] }

I do need the c.id in the end. but not displayed in the dropdownlist.
And it’s
shown like this now: “Company - FirstName Lastname3”
The “3” being the id of the contact. Do i need to fill the
@project_contacts
in a different way, or address the select statement data input in a
different
way? What would be your choice for ease of use?

Thanx,

Regards.

On Thursday 05 January 2006 14:34, Chris H. tried to type something
like:

2], … ]

object @project_contacts with “Name” from table Companies and “Firstname”

My $Grtz =~ Gerard;
~

:wq!


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


“Who cares if it doesn’t do anything? It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process …”

My $Grtz =~ Gerard;
~
:wq!