Displaying 20 results from an estimated 30000 matches similar to: "has_many in a view"
2008 Mar 12
2
Building a view for a 3 model has_many relationship
I''m working with three models:
- Charge. has_many :budget_plans
- BudgetPlan. belongs_to :charges, :rollups
- Rollup. has_many :budget_plans
This works out perfectly. A budget plan contains the ID of a charge and
rollup and then there''s a 3rd attribute for hours. So working with data
is no problem.
My budget plan scaffold works nicely so I can select a charge, select a
2007 Feb 05
6
Viewing object associated via "has_many :through"?
This is my first question to the Forum. Ive set up these associations:
class Playlist < ActiveRecord::Base
has_many :playlists_tracks, :dependent => :destroy
has_many :track_ones, :through => :playlists_tracks, :source => :track
has_many :track_twos, :through => :playlists_tracks, :source => :track
end
class Track < ActiveRecord::Base
has_many
2006 Apr 20
3
has_many :through with has_many/has_many join models
It seems that using a join model that joins with two has_many''s will
fail to generate proper SQL
class StudentSemesterRecord < ActiveRecord::Base
belongs_to :semester
has_many :discipline_records, :through => :semester
end
class Semester < ActiveRecord::Base
has_many :student_semester_records
has_many :discipline_records
end
class DisciplineRecord <
2006 May 16
0
Possible bug: ActiveRecord::Base::has_many fails for String arguments.
Hi
I''ve noticed ActiveRecord::Base::has_many fails for String arguments.
The following code works when all arguments to the
ActiveRecord::Base::has_many calls are Symbols:
class Country < ActiveRecord::Base
has_many :country_products, :dependent => true
has_many :products, :through => :country_products
end
ruby script/console
>> Country.find_all.first.products
2006 Apr 03
0
has_many questions
My application has two models I''d like to have multiple join tables
between, Users and Groups. Users have the ability to subscribe to a
Group, while a Group would like to know its membership.
Additionally, a User can administer several Groups and a Group should
know about its several Administators (Users).
I have the following declarations:
class Administrator <
2006 Mar 24
2
Change to has_many :through associations
Hi everyone. I''ve made a default change to has_many :through
associations that I felt was important to make before they''re
released. This is after some tickets and confusion I''ve seen
regarding has_many :through.
class Connection < ActiveRecord::Base
belongs_to :user
belongs_to :channel
end
class Channel < ActiveRecord::Base
has_many :connections
2010 Jan 25
0
has_many, :finder_sql, setting attributes
Hi all,
My question is somewhat complicated, but bear with me. My project has a
number of models: User, Program, and Team. Users belong to multiple
Programs. Programs have multiple teams, but Teams belong to one
program. For each Program a User belongs to, he can belong to multiple
Teams. (Think of this in an athletic context where users are athletes,
programs are universities). So my
2009 Nov 12
0
Problem with has_many :through, :uniq => true with polymorph
Didn''t have quite enough space to describe it there...basically i''m
having a problem with the :uniq option in my tags.
I''m using acts_as_taggable_on_steroid which adds these associations to
my Resource class:
Resource
has_many :taggings, :as => :taggable, :dependent => :destroy, :include
=> :tag
has_many :tags, :through => :taggings, :uniq => true
2005 Dec 26
2
Dynamic order on has_many relationship?
I was wondering if it''s possible to some how control the :order given
on a has_many depending on another attribute?
Or do I need to just create multiple has_many relationships pointing
to the same table but with different orders and then select which one
I use in the controller instead?
e.g
class Category < AR::B
has_many :products, :order => //something magical?//
end
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 Feb 07
0
Newbie question: has_many to multiple classes
Hi,
I''m trying to work out how to tackle a particular problem in rails.
I have some data. A lot of data (well not NSA style a lot of data, but
a lot for me: 1Gb at the moment, more to come).
I''m building a ruby application to process and view this data, and have
been working round using rails as a front end - do the heavy lifting
using some maths libraries, then use rails to
2007 Jan 05
1
(Enhancement?) for self referential has_many :through, w/ scoped create...
We have a User model and a Connection model which basically represents
edges in a digraph (User to User, self-referenctial). Each of these
edges can have a :connection_type which is currently just a char(1).
has_many :friendships,
:class_name => ''Connection'',
:foreign_key => "source_user_id",
:conditions =>
2006 Apr 04
1
Manipulating has_many :through associations
Hi,
I haven''t done any associations before, so please forgive my incorrect
use of terminology...
If I set up a has_many :through association, can I manipulate the
associated instances directly (like an Array), or do I need to
manipulate the join model?
For example, suppose I have two classes and the associated join model:
class foo
has_many :foo_bars
has_many :bars, :through
2006 Aug 16
1
Naming rights_roles join model using has_many :through and polymorphic associations
Hi.
I have a couple of best practices questions regarding polymorphic
associations, naming join tables and user permissions.
Currently I have implemented the user authentication model from the
rails recipes book. Basically it goes something like this:
MODEL CLASSES:
class User < ActiveRecord::Base
has_and_belongs_to_many :roles
end
class Role < ActiveRecord::Base
2010 Jan 27
2
has_many, through with nested models?
First the data model:
class Forum < ActiveRecord::Base
has_many :topics, :dependent => :destroy, :order => ''created_at
desc''
end
class User < ActiveRecord::Base
has_many :topics, :dependent => :destroy
has_many :comments, :dependent => :destroy
has_many :replies, :dependent => :destroy
end
class Topic < ActiveRecord::Base
belongs_to
2006 Jul 04
2
has_many working correctly only on reload!
I have this code that is using svn externals with rails EDGE working
fine for the past couple of months. A couple of days ago, this code
died. Even after deleting vendor/rails, this code doesnt work:
class Tag < ActiveRecord::Base
has_many :taggings
has_many :events, :through => :taggings
has_many :users, :through => :taggings
end
class User < ActiveRecord::Base
# Virtual
2006 Jul 21
0
has_many :through and form parameters
Hi,
The standard setup:
class Task:
has_many :studies, :class_name => "Study"
has_many :datasets, :through => "studies"
class Dataset:
has_many :studies
has_many :tasks, :through => ''studies''
class Study:
belongs_to :task
belongs_to :dataset
Now, if I have an edit view for my Task, is it possible to set up the
form so that in the
2006 Jun 09
0
has_many / : through / check_box - update problems
Can anyone help me with this, which has been making me tear my hair out for 2
days now ?
I have the following classes using has_many :through relationships...
(I''ve changed the class names to make it easier to understand, so don''t
beat me up about naming conventions ;) )
class Movie < ActiveRecord::Base
has_many :localdetails
has_many :territories, :through=>:rights
2008 Nov 19
0
has_many through select box in form
Gentlemen,
I have searched the group and have not found any post that clarifies
thsi s=issue to me. Please forgive me in advance if I missed
something.
I have 3 models:
Ticket
has_many :citations, :dependent => :nullify
has_many :violations, :through => :citations
Violation
has_many :citations, :dependent => :nullify
has_many :tickets, :through => :citations
Citation
2010 Aug 26
0
Eager loading a has_many :through (Rails3)
Hello all,
I''ve been trying out Rails 3 and can''t get past this issue:
I have a simple has_many :through:
class Author < ActiveRecord::Base
has_many :author_series
has_many :series, :through => :author_series
end
class Series < ActiveRecord::Base
has_many :author_series
has_many :authors, :through => :author_series
end
In my controller I would like to