Displaying 20 results from an estimated 8000 matches similar to: "relationing has_many, belongs_to"
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
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
2008 Feb 22
4
has_many and belongs_to in rails 2.0.2 (child.Parent) is not working
Hi All
I have 2 models working well in rails 1.2.6 :
class TypeService < ActiveRecord::Base
has_many :Services
end
class Service < ActiveRecord::Base
belongs_to :TypeService
end
I was able to get the name of the service with Rails 1.2.3:
s = Service.find(1)
name_type_service = s.TypeService.name <<-- Now with rails 2.0.2
that doesn''t work
With rails 2.0.2
s
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 Jan 09
1
Saving an upload
I am creating a database for movies (films) and television shows (shows)
that will have has_and_belongs_to_many relationships with the pictures
table.
CREATE TABLE screenshots (
id serial NOT NULL,
filename character varying NOT NULL,
content_type character varying NOT NULL,
primary key (id)
);
CREATE TABLE films (
id serial NOT NULL,
name character varying NOT NULL,
2006 Feb 03
3
My associations are coming out nil.
I''ve got a fairly simple system with a table for my Users that
includes a CountryId field which looks up to the CountryId field of my
Country table. What I would like to happen is for my Rails
application, which contains models for both User and Country, to be
able to draw the dropdown list of available countries on the edit
page, like it does in all the tutorials.
My model classes look
2006 Apr 07
5
Confusion about has_many / belongs_to ...
I have a table called players and its model Player, and I have a table
called games and its model Game.
In the games table I have:
player1_id int(11)
player2_id int(11)
I want the tables to be associated so that I can access the player
objects using table.player1 and table.player2 rather than having to
lookup the objects based on the ids.
I am not sure how to go about this but I suspect I
2006 Feb 16
1
HABTM -VS- belongs_to/has_many, for self-referential joins
Ok, David says on page 241 that sometimes a many-to-many relation with
attributes are better implemented as an actual model instead of using HABTM.
Well, I''ve got that situation and I can''t figure it out.
All of the examples in the book have HABTM examples between 2 different
tables, but I want to have a HABTM relation on 1 table with itself. (e.g.,
if I have a table Things,
2006 Jun 27
3
belongs_to <parent name>, :foreign_key modifier not working
All,
I have two ActiveRecord objects.
TargetList has_many Targets
Targets belongs_to TargetList
I''ve specified
belongs_to :target_list,
:foreign_key => ''DataSetID''
Queries generated by various methods in target_list do not seem to see
the
foreign_key name and keep trying to query my Target table using
"target_list_id" (the default foreign
2006 Jun 29
4
Multiple belongs_to
Let''s say I have a catalog with hotels. Each hotel belongs to a
category (4-star, 5-star etc.) This is it''s official category.However,
there is also a category that users assign and a category that
"independent reviewers" assign. So I have this:
hotels {
id,
category_id,
reviewer_category,
user_category
}
categories {
id,
name
}
class Hotel <
2005 Dec 14
5
belongs_to and multiple foreign keys
Hi all,
I''m confused about how I''m supposed to specify a belongs_to relationship when
the table includes multiple columns that reference the same parent table.
In my case I have a "schedules" table with "opened_by" and "closed_by" columns,
that both reference the "users" table. In theory, they can be two different
user ids.
table
2006 Feb 27
4
2 belongs_to to the same parent table
Hello!
I have 2 table: users and buddies
User: id, name, ...
Buddy: id, user_id, user_buddy_id, ...
So if you have 2 users 1,jack and 2,fred and fred is a buddy of jack,
there is a Buddy object: id=1, user_id=1, user_buddy_id=2
I can declare only one belongs_to in Buddy and one has_many in User. And
there is conflict if I had the second one (the first one is discarded)
class User
has_many
2011 Sep 16
4
belongs_to not working as
Hi,
I have a model tests_user and score which are associated with each other by
has_one and belongs_to association.
class TestsUser < ActiveRecord::Base
has_one :score, :foreign_key => :reg_no
end
class TestsUser < ActiveRecord::Base
belongs_to :tests_user, :foreign_key => :reg_no
end
where reg_no is a unique field in both the table!
score = Score.find(:first) gives me
2011 Jul 11
36
has_many and belongs_to association
Hi ,
I want to test the one below but I got the problem
belongs_to :name, :class_name => "Phrase", :foreign_key => "name"
in my test
context "test"do
should have_many :phrases
end
in language.rb
belongs_to :name, :class_name => "Phrase", :foreign_key => "name"
error is
1) Failure:
test: check has_many and belongs_to
2006 Jul 23
4
has_many AND has_many :through ?
Hi,
I am working on a scheduling app and I have a perpelextion (new word).
I am wondering if the problem is my data model
I have Users.
Users can create Events.
Users can be invited to Events created by other Users.
So...
user.rb
class User < ActiveRecord::Base
has_many :invitations # invitations to other users'' events
has_many :events, :through => :invitations # all events
2006 Aug 02
2
Self-Referential has_many :through
Hello all.
I am trying to create a self-referential has_many :through. I used the
following site as a guide
http://blog.hasmanythrough.com/articles/2006/04/21/self-referential-through
but it still doesn''t appear to be working. I have two models. Person and
Relationship. A person has many contacts (Which is another person)
through relationships
class Person < ActiveRecord::Base
2005 Apr 27
4
has_many syntax
Hi all,
I have the following inside of an AR class definition:
relationships=ActiveRecord::Base.connection.select_all(my_relationships_sql)
relationships.each do |relationship|
has_many RelatedItems, :class_name => relationship[''RelatedClass''],
:foreign_key => relationship[''ForeignKey'']
end
This kind of works, but how can I assign the name of the
2006 Jul 10
10
has_many :through and foreign key parameters
I just took my HABTM and turned it into a :through since my join table
has another "non-joiny" attribute.
I went from this:
has_many_and_belongs_to :jobs, :join_table => ''tablename'',
:foreign_key => ''x'',
:association_foreign_key => ''y''
to this:
has_many :jobs, :through =>
2006 Apr 21
3
polymorphic,has_many through can not work?
Josh Susser tells in his blog that the opposite direction of polymorphic
will get into trouble together with has_many through.
This is the url:
http://blog.hasmanythrough.com/articles/2006/04/03/polymorphic-through
I do that according to Josh Susser''s procedure:
class Tagging < ActiveRecord::Base
belongs_to :tag
belongs_to :taggable, :polymorphic => true
belongs_to
2008 Jun 13
6
Newbie question on has_many
I have two classes: a Widget and a User. The User has an id that is
referenced in two places on the Widget: owner_id and operator_id.
How should I structure that reference for has_many?
Thanks folks - I appreciate any help on this.
--David
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: