similar to: Can A Model Have Many belongs_to?

Displaying 20 results from an estimated 10000 matches similar to: "Can A Model Have Many belongs_to?"

2006 Jun 03
8
confused about ActiveRecord relationships
I am very confused 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
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
2006 Jul 08
2
Creating/Saving dependent objects
Folks, Am new to RoR and am building an example to get myself familiar. I am running into a simple issue while creating a user registration page. I have a User and Address models defined as below (partial/relevant code included below). User has_one address and Address belongs_to user. I have a foreign key defined in address table that refers to user(id) In a form I take in username, password,
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 Aug 03
3
Relationships between models.
Hi All, I think Im having a mental block here. For some reason I just cant get my head round relationships. What I have is the following. 4 tables 1) Hosts 2) Software 3) OperatingSystem 4) Company In my terms (which are most likely wrong) a company can have lots of hosts, a host has lots of software, a host has one operating system. So should my models have the following relations in them?
2008 Apr 18
3
has_many and belongs_to with non-primary foreign keys
Hi, I''m having a bit of trouble with my first Rails app. ---- I have two tables: create_table :items do |t| t.column :created_at, :timestamp t.column :user_id, :int t.column :text, :text end create_table :users do |t| t.column :user_id, :int t.column :name, :string end ---- I''m trying to use the "user_id" field to link both tables, with each user
2006 Oct 30
2
It this possible: finder_sql-like behavior for belongs_to?
Guys, I have a need to support as has_many/belongs_to relationship on a legacy(kind of) schema. The reason I say kind of is that the schema does have "id" columns that are used in many associations, but this particular has_many/belongs_to association needs to support different ones. I''ve attached to code at the end of this email. Suffice it to say I need to use the standard
2006 Jul 11
1
counter_cache, has_many and belongs_to
I am a bit confused about counter_cache here. The API docs http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html say that only the belongs_to association can take the :counter_cache option. When I try to use it on a has_many I get an "unknown key(s): counter_cache" error. Why would this be the case? belongs_to means that this model has a field with an id
2009 Nov 06
0
Nested objects not propagating from view
I thought I had this fixed, but apparently not. It works okay from the console, but not from the view. I have the following: # partial schema create_table "users", :force => true do |t| t.string "login", :null => false t.string "first_name" t.string "last_name" t.string "email", :null => false
2006 Jan 09
3
Design Question
I am sure some of you can give me an insight into this. This is more towards the database design for the scenario below: Say for example, I have a person table and this 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
2006 Feb 20
1
belongs_to, has_one, has_many question (again?)
Hi All, Probably this has been asked numerous times, I apologize already! Can somebody point me to a good tutorial on how Rails works with relations? I know about database design and normalization, I also know about programming in general (and OOP for that matter). Only thing I can say is that I''m following the "Four days on Rails" tutorial by John McCreesh. He writes
2006 Apr 03
2
Problems with STI in has_many/belongs_to in Rails 1.1
I have a problem that surfaced in my attempt to upgrade my application to Rails 1.1. We have a STI model on the "belongs_to" side of a has_many/belongs_to relationship. All my unit tests for this model pass, and the relationships all seem to work fine. But in my functional tests, I''m getting errors. I''ve traced it back into the call to the has_many
2006 Jan 20
1
stack level too deep from has_many / belongs_to relationship
I have the following 3 models (2 models joined by an intermediate): 1. class Exercise < ActiveRecord::Base 2. has_many :routines, :class_name=>''RoutineExercise'' 3. end 1. class Routine < ActiveRecord::Base 2. has_many :exercises, 3. :class_name=>''RoutineExercise'', 4. :order=>''position'' 5. end 1. class
2006 Mar 22
2
habtm vs. has_many/belongs_to
In AWDWR David says (pg 232), "When a Join Wants to Be a Model: While a many-to-many relation with attributes can often seem like the obvious choice, it?s often a mirage for a missing domain model. When it is, it can be advantageous to convert this relationship into a real model and decorate it with a richer set of behavior. This lets you accompany the data with methods. As an example,
2009 Jun 27
1
Problem with :touch in belongs_to
I''ve read in rails api that there is a touch parameter and I want to use it in my application. I have something like that class User < ActiveRecord::Base has_many :phones after_update :updated def updated ... end end class Phone < ActiveRecord::Base belongs_to :user, :touch => true end I want that every change of any phone number would change User updated_at
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
2006 Apr 18
1
habtm and belongs_to one table
I have the following: Posts belong to a User Posts may be Monitored by many Users How do you characterize this? class Post < ActiveRecord::Base belongs_to :user has_many :monitors class Monitor < ActiveRecord::Base has_many :posts, :as => user class User < ActiveRecord::Base has_many :posts # when a user *does* a post belongs_to :monitor, :polymorphic => true --
2023 Jul 26
2
Rename Computer on Domain
I can report that the computer renaming worked. As it turned out, only the cn was incorrect ... ldbsearch -H ldap://DC1 -UAdministrator 'CN=DT06' dn: CN=DT06,OU=Desktops,OU=Computers,DC=domain,DC=com objectClass: computer cn: DT06 operatingSystem: Windows 10 Pro displayName: WH23$ sAMAccountName: WH23$ ... so a simple LDAP rename worked ... ldbrename -H ldap://DC1 -UAdministrator
2006 Apr 25
3
belongs_to and has_many
I know this has been rehashed many times, but I don''t get it. I can''t find it documented to were I understand all the parts. I can make this work using Rails database design conventions, but in this case I am not able to do that. I find examples, but the ones I find do not follow the conventions. They also do not give enough information to understand what is going on. In