Displaying 20 results from an estimated 30 matches for "address_id".
2006 Jun 03
8
confused about ActiveRecord relationships
...onfused about where to put the belongs_to and the has_one
(and other relationship identifiers). I have read the RDoc and the
agile book many times about this and I think i still see it backwards.
Let me outline my app so you have an understanding...
I have 2 tables:
Schools { id, school_name, address_id }
and
Addresses { street1, street2, city, state, zip, country }
*** this is the way that makes sense to me but it doesnt work ******
Models
school.rb
has_one :address
address.rb
belongs_to :school
View for School
<% for school in @schools %>
<td><%= school.school_nam...
2006 Feb 03
6
Saving a User Object while in the Address Controller
...e
the address.
This isn''t the exact code, but it shows what I am trying to do.
class AddressesController < ApplicationController
def create
@address = Address.new(params[:address])
saved_address = @address.save
@user = User.find(params[:id])
@user.address_id = @address.id
saved_user = @user.save
end
end
User.save keeps on returning false.
Any ideas why? I can access different attributes of the user, so I know
that the proper user is getting returned from the find.
In my user class I have attr_accessible :address_id so I should be able
t...
2006 Jan 09
3
Design Question
...person can have different address types.
One could be Home and the other could be say Office.
Should be model this
Table people
id
fname
lname
Table addresses
id
person_id
addr1
addr2
....
or
Table people
id
fname
lname
Table addresses
id
addr1
addr2
Table persons_addresses
person_id
address_id
Are there any tutorial that explains these concepts?
Any help is highly appreciated.
Thanks
Silvy Mathews
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060109/bf2a8ae0/attachment.html
2006 Feb 28
2
Need help with a Power Find()
I was hoping someone would be able to help me with creating a method.
I have two tables. What I am trying to do is create a list of all the id''s
from table2 that aren''t currently referenced by Table1''s address_id column.
That way, when I create a new customer I can have a drop down list in the
view of all the addresses that are not currently being used.
##### Database #####
Table1
id
name
address_id
Table2
id
address
##### Models #####
class Table1 < ActiveRecord::Base
belongs_to :table2
end
-------...
2006 Jul 02
1
multitable form
...a table in my
database and then I generate pretty forms on a webpage.
I would like to know how I can do to make forms who interact with more
than one table.
For an example lets imaging the 4 folling tables :
type_of_user [id, typename]
users [id, username, firsname, lastname, type_of_user_id, address_id]
where type_of_user_id is a foreign key who references the type_of_user
and where
address_id is a foreign key who references the addresses table.
addresses [id, street, number, box, zip, country_id] where
country_id ....
table countries [id, countryname]
I wanna visitors to be able to register t...
2006 Jul 05
19
associations question
Hello,
I have a People table and a Addresses table. A person can have one or
more addresses, but should at least have one, so there is a address_id
field in People.
Now, I would like to have a form to fill the name of a new person and
its address from the same place. I could use person.address.country, for
example (it works), but I would like to simply use person.country for
some reasons (I have a generic controller and generic views whi...
2006 Jan 12
2
Can A Model Have Many belongs_to?
...poor form or what
the best practices are around it. The documentation says that the
foreign key should be in the table that belongs_to the linked table so
that the linked table data is available via the object model. (i.e. if
system belongs_to address then you would have a foreign key
system.address_id so that you can do system.address.state or
system.address.zip, etc.
But if I have data in several other tables that I wish to access this
way, it would require several belongs_to declarations in the same model.
For my circumstances I have a system (represents a computer) table that
is linked t...
2006 Jul 08
2
Creating/Saving dependent objects
...</fieldset>
</div>
*
I get the following error message on the page from the Exception (and log
file)
*Mysql::Error: #23000Cannot add or update a child row: a foreign key
constraint fails: INSERT INTO users (`hashed_pwd`, `last_login_at`, `salt`,
`username`, `firstname`, `lastname`, `address_id`, `company_id`,
`login_count`, `created_at`)
VALUES(''fce4d31d2ddf5b0ffd122189b9d575362f79c9c9'', ''2006-07-07 23:29:09'', ''
302121320.0514656016603112'', ''rohant'', '''', '''', 0, 0, 0, ''2006...
2006 Feb 08
5
beginner - problem with understanding relationships
Hi folks,
I''m new to this... so hopefully someone can help me.
I have a few objects... Property and Address and Landlord... where a
Property has an address and a landlord has an address also.
I''ve modelled this in the db with the properties table having an
address_id and the landlord table having an address id.
My rb looks like:
class Property < ActiveRecord::Base
has_one :address
end
class Address < ActiveRecord::Base
end
the controller looks like:
def create
@property = Property.new(params[:property])
@property.address = Address.new(par...
2006 Jul 04
13
NewBie question
Hi,
I m very new to Ruby.
I bought a book "Ruby on Rails" and I think I understand some concepts.
My question is :
Is there a way to not use "Cookies" or "Sessions Variables" to keep some
information about the user.
I ask this question because I would like to prevent some cases where the
user browser won''t accept cookies.
I m from Asp 3.0, and I
2006 May 17
4
NOOB: Representing linked objects in one form
Given two models:
User
:name
:email
:address_id # foreign key
Address
:line_1
:line_2
:city
etc.
I want to have a form allowing a user to register, in which she''d enter
an address as well, but how do I go about combining both objects into
the one form?
I''m new to this and following along with the Agile Rails book...
2008 Sep 08
1
ActiveRecord::StatementInvalid Error
...omerid=#{session[:customerid]} and enabled=''1''"), :id, :address,
{},
{:onchange=>"showcompletedetails()", :onclick=>remote_function(:update=>"", :url=>{:action=>"setaddress"},:with
=> "''id='' + $
(''address_id'').value"),:size=>"5",:class=>"dropdown",:style=>"width:
100%;border:1px solid #0099cc;" }%>
"
Thanks
Mohd Anas
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Gro...
2008 Jul 21
3
Asymmetrical HABTM(?)
What is the best way to set up a relationship between two tables where
table-1 has a one-to-one relationship with table-2 but table-2 has a
one-to-many relationship with table-1?
For example, suppose there is an events application (seminars, forums,
conferences, etc). Each event has only one address but since many
events can occur at the same location throughout the year, a given
address can
2009 Nov 06
0
Nested objects not propagating from view
...t.string "password", :null => false
t.integer "contact_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "contacts", :force => true do |t|
t.string "company_name"
t.integer "address_id"
t.integer "phone_areacode", :limit => 3
t.integer "phone_prefix", :limit => 3
t.integer "phone_suffix", :limit => 4
t.integer "phone_extension", :limit => 5
t.string "website"
t.integer "b...
2006 May 17
2
Association data clobbering (foreign keys too?)
Can someone please confirm or correct the following statements?
If I have the following tables
create table as (id int, [...], b_id int);
create table bs (id int, [...], a_id int);
create table as_bs (a_id int, b_id int);
and the associations woould be defined like this
class A << ...
habtm :bs
belongs_to :b
end
so my Model A has a habtm collection of Bs *plus* a direct
2005 Dec 16
6
managing belongs_to fields in a form
Hi all,
I cannot find a clean way to create/edit an object that ''belongs_to''
another one, just by using form fields.
I always need to explicitely unassemble it, store the master id in a
hidden field, and then refetch the master from its id, and put it back
in the object.
To summarize:
I want to create a new member, for a given project
@project= ...
@member =
2006 Jul 20
0
Getting joined collections on a form
...@addresses = Customer.find(params[:invoice_customer_id]).addresses
end
customer.rjs
page[:customer].replace_html :partial => ''customers/customer'', :object =>
@customer
page[:customer].visual_effect :highlight
customer.rhtml
<%=
collection_select(:invoice, :address_id, @addresses, :id, :street,
{:include_blank => true},
{
:onchange => remote_function(:url => { :action => "get_address"},
:with => "''invoice_address_id=''+ $F(''invoice_address_id'')")
})...
2006 Feb 17
0
Model relationships in tests
I''m finding that its a pain to create yml files for tests where there
are relationships between tables/classes.
For example, I might have something like this:
vehicle.yml
red_ford:
id:1
owner_id:2
owner.yml
ford_owner:
id:2
address_id:5
address.yml
home_address:
id:5
etc.
To build up complex test relations, I have to edit all three files,
keeping track of the ids / fkeys for each test case. I''ve thought about
skipping foreign keys altogether in the fixtures and creating the
relations programmatically in the...
2006 Feb 19
2
Another "escaping" problem
...r2, addresses.`name` AS t0_r1,
events.`meet_at` AS t1_r3, addresses.`phone_number` AS t0_r2,
events.`created_at` AS t1_r4, addresses.`phone_service` AS t0_r3,
events.`location_id` AS t1_r5, addresses.`user_id` AS t0_r4 FROM
addresses [" LEFT OUTER JOIN addresses_events ON
addresses_events.address_id = addresses.id LEFT OUTER JOIN events ON
addresses_events.event_id = events.id "]WHERE (addresses.`phone_number`
= ''6129641828'' )
Notice the bit in the middle that looks like a list of strings ["..."].
Any clues?
Thanks,
-elan
--
Posted via http://www.ruby-...
2006 Feb 28
0
Confusion with counter and single table inheritance
...`vents_count` int(11) default ''0'',
`created_at` timestamp NOT NULL default CURRENT_TIMESTAMP on update
CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL default ''0000-00-00 00:00:00'',
`total` decimal(12,2) unsigned default ''0.00'',
`address_id` int(11) NOT NULL default ''0'',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vents` (
`id` int(10) unsigned NOT NULL auto_increment,
`type` char(20) NOT NULL default '''',
`width` int(10) unsigned default NULL,
`height` int...