Displaying 20 results from an estimated 10000 matches similar to: "Newbie question on has_many"
2010 May 14
4
Tricky model situatione
I have two models Club and users. users are regular authenticated
users and some of them might create a club. A club can also have
members (essentially users) and there are attributes and models that
apply to member but not to users.
Here is what I have right now.
Club => belongs_to :user
User => has_many clubs (since a user can host multiple clubs).
Now how do I fit this member model
2006 May 20
7
Polymorphic, many-to-many, self-referential data model
No matter what I try I''ve been unable to work how to get this to work with
the cool ActiveRecord helpers. I''m not sure if it''s possible, Josh Susser''s
blog suggests it is, but damned if I can work it out...
I have:
Container which can contain one or more Element. An Element is a polymorph
of either a Container or a Chunk. An Element can exist in one or more
2009 Jul 29
5
[newbie] double relationships in database
I have the following tables
teams
id :string
name :string
and
matches
id:
home_team :team_id
visitor_team :team_id
how can I reflect that kind of relationship in a RoR model?
thanks and keep up the good work.
2006 Nov 26
5
associations help?
I have Users who can "own" Projects. There is only one owner. Users in
general can be authorized to view certain projects. Here is my initial stab
at this:
class User < ActiveRecord::Base
has_many :projects # ownership
has_many :project_viewers, :dependent => :destroy
has_many :projects, :through => :project_viewers, :uniq => true
...
end
class
2006 Apr 02
7
RANT: belongs_to -> refers_to
Every once in a while, I pipe up and whine that "belongs_to" should really
be ''refers_to" [http://dev.rubyonrails.org/ticket/2130]. It''s time again.
I''ve got a bunch of stuff going onto eBay, so, like any good engineer, I
don''t just post it manually: I design a Rails-based inventory database that
creates a semantically-correct XHTML/CSS auction
2006 May 14
4
searching on foreing keys
Hey all,
I''m using a simple search function. It''s working
great except for foreign keys.
I have one table pets (id,name,owner_id)
and another table people(id,name)
owner_id being a foreign key of pet pointing to people name.
here it is on the pet controller:
@paginator, @pets= paginate(:pets, :conditions =>["name OR owner_id
like
2008 Jul 15
9
Beginner Question.
I''m just getting into RoR, coming from a long PHP background. So far I
LOVE IT!
I''m hitting a roadblock with updating my mysql database. For
simplicities sake, I have 2 tables and here are the relevant columns.
Table Users
id
name
email
Table Issues
id
createdby
assignedto
reportedby
In my models I have everything mapped properly I believe.
When I try to update the
2007 Jul 18
10
Rails - Mock going out of scope?
Hello list,
I think I have a rails related RSpec problem with a mock going out of
scope on a recursive call to a model.
The code is at: http://pastie.textmate.org/79821 if you want to see it
highlighted. I have pasted it below as well.
Basically, I have an acts_as_nested_set model called "Node", which
works fine. I have a function which finds the language name of the
node instance.
2006 Mar 31
3
Complex Through Statement
Quick Overview:
I have an ''Employee'', some ''Merchants'' and some ''Products''. A
''Merchant'' has many ''Products''. An ''Employee'' has multiple ''Merchants'',
depending on their relationship. For example, the Employee may be the
enrollment contact for one merchant and the
2006 Nov 02
4
Still Having Problems With :through When Going To Same Table... Help... please :-(
I am having a problem with doing a :through that goes back to the same table.
The following are my two classes:
>>>>>
class User < ActiveRecord::Base
has_many :spanks
has_many :spanked, :through => :spanks, :source => :spanked_user
has_many :was_spanked_by, :through => :spanks, :source => :user
end
class Spank < ActiveRecord::Base
belongs_to :spanker,
2006 Feb 14
6
Multiple associations to the same class
Hi,
I cannot seem to create associations like this:
class Project < ActiveRecord::Base
belongs_to :manager, :class_name => ''User'', :foreign_key => ''manager''
belongs_to :liaison, :class_name => ''User'', :foreign_key => ''liaison''
end
p = Project.new
p.manager
=> 1
trying to retrieve associated objects
2006 Jul 07
3
Newbie Model question (HABTM?)
All,
If I have a table that has several discrete fields that all point to
the same associated field, how do I model it.
Specifically,
If I have a project table that has 2 fields: specifying_company, and
responsible_company.
And one table of associated companies, how do I do the :belongs_to /
:has_many stuff
ie. For a given project company A may be writing the spec, but company
B may be paying
2006 Mar 29
3
Self-referential many-many joins with :through
I thought I had this nailed but.. now I''m seeing spots..
I''ve included my models below, feel free to ignore them. I''m really
just after an example that works. I couldnt find one on the wiki...
which is fair enough considering Ricks patch:
http://dev.rubyonrails.org/changeset/4022 that fixed them only went
through 5 days ago..
Cheers
-henster
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 Dec 19
4
need some help designing my messaging system
I am trying to create a messaging system for my users but I''m having a
hard time designing my db. This is what i have in mind, but I am not
sure if its the best approach.
user has_one inbox
user has_one outbox
inbox has_many messages
outbox has_many messages
inbox table
user_id
outbox table
user_id
messages table
box_id (refers to either inbox or outbox - how?)
from_id
to_id
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 May 28
7
Self-referential has_many :through relationship
Hi,
I have a self-referential has_many :through relationship setup to
track relationships between users. Basically relationships are
modeled as a join table with an extra column ''relation''.
create table relationships (
user_id integer unsigned not null,
friend_id integer unsigned not null,
relation char(1) not null,
)
--- relations ---
f = friend
r = request to
2011 Jan 15
3
has_many :through with Single Table inheritance
I have the following model structure setup.
class User < ActiveRecord::Base
end
class Parent < User
has_many :relationships
has_many :children,
:class_name => "Student",
:through => :relationships,
:conditions => "related_as = ''parent''"
end
class Student < User
has_many :relationships
2006 Mar 29
4
:through alternate
I''d like to use :through to create a web of associations like:
class Thing < ActiveRecord::Base
has_many :child_things, :through => :thing_thing
has_many :parent_things, :through => :thing_thing, :some_other_option?
end
class ThingThing < ActiveRecord::Base
belongs_to :thing
belongs_to :child_thing, :class_name => ''Thing'', :foreign_key =>
2007 Oct 16
8
Using multiple foreign keys in views
I have a model, Game, that has_many :teams. There''s a home team and an
away team. I created two foreign keys, so each game can have two teams
associated with it. Here''s the Team model:
class Team < ActiveRecord::Base
belongs_to :game,
:class_name => ''Game'', :foreign_key => ''hometeam_id''
belongs_to :game,
:class_name =>