Displaying 20 results from an estimated 30000 matches similar to: "Pre-populating a has_many relationship?"
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
2007 Oct 18
0
Getting the through items from a has_many :through :uniq relationship
Getting the through items from a has_many :through :uniq relationship
In a nutshell, I have been using the has_many :through :uniq
relationship, and I want a DRY way to list the join model objects.
Currently, my objects include taxon objects, toxin objects,
data_object objects, and taxon_toxin_citation objects ("citation" is
another word for data_object). A taxon has many data objects,
2012 Jun 18
0
Creating an object with a nested has_many :through relationship
I have 3 models that define members, groups and the subscriptions: Member,
Group, and GroupMember.
class Member < ActiveRecord::Base
> has_many :group_subscriptions, class_name: "GroupMember"
> has_many :groups, through: :group_subscriptions
> attr_accessible :email, :password
> end
> class Group < ActiveRecord::Base
> has_many :member_subscriptions,
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
2010 Jan 08
1
problem using build with has_many :through relationship
Hello all,
I''m having problems creating a new record with has_many :through
My application is quite complicated so I''ll try to explain it as easy as
I can.
I have a many to many relationship with Projects, IRBs and Reviews.
Where reviews is the joined model.
In the new project view, I have a link (add IRB). This will add an a
list of IRBs to the new project form.
I have visited
2006 Aug 01
2
has_many :through a belongs_to relationship
I have users who belong to a group. I also have a room that belongs to
a group. I want to use a has_many through association to link the room
and the users as such:
class Room < ActiveRecord::Base
belongs_to :group
has_many :users, :through => :group
end
The SQL generated for the search is incorrect:
SELECT users.* FROM users INNER JOIN group ON users.group_id =
groups.id WHERE
2005 Dec 27
0
How do I combine :finder_sql and :conditions to perform a sub-search on a custom has_many relationship?
I''m sure there''s something right under my nose that I''m missing.
I have two tables with two parallel one-to-many relationships. I wish
to use the :finder_sql parameter to essentially ''or'' the two foreign
keys.
What isn''t working for me is performing a ''sub-search''.
Let''s say the tables are "stores" and
2011 Jun 22
0
has_many relationship in Gem
Hello,
I am creating a gem in which I need to add a new has_many
relationships:
...
included do |base|
base.has_many :foos
end
def some_method
self.foos #
end
...
Here Foo is a model I created and it is places in app/models/Foo.rb
I wonder if I can use syntax like the line marked with #?
If yes, I got NoMethodError for using "self.foos" when writing rspec
2006 Jul 25
1
save trouble with has_many belongs_to relationship
I have a bit of code in a controller that looks like this:
@current_festival.monitor_preferences.each do |pref|
if pref.user_id == @me.id
pref.preference = params[:monitor_pref]
#pref.save
end
end
@current_festival.save_with_validation(false)
the Festival class has_many :monitor_preferences
the MonitorPreference class belongs_to :festival
In the configuration above, the
2006 Sep 08
1
has_many relationship extensions and scoping rules
Hi all !
Is this supposed to work ?
class Email < ActiveRecord::Base
has_many :to, :class_name => 'Recipient', :conditions =>
"recipients.source = 'to'" do
def create!(*args)
with_scope(:create => {:source => 'to'}) do
super
end
end
def build(*args)
with_scope(:create => {:source => 'to'}) do
2005 Dec 23
2
has_many and belongs_to relationship error
Hi i am getting following error
ActiveRecord::StatementInvalid in Blog#index
Showing app/views/blog/index.rhtml where line #10 raised:
Mysql::Error: #42S22Unknown column ''posts.user_id'' in ''where clause'':
SELECT * FROM posts WHERE (posts.user_id = 4)
Extracted source (around line #10):
7: <div class="separator"> </div>
8:
2006 Jul 21
3
acts_as_ferret with has_many relationship
Using Ferret and the acts_as_ferret plugin, I would like to retrieve
results based on models descended from a parent model:
class Post < ActiveRecord::Base
acts_as_ferret :fields => [ ''title'',
''body'',
:post_author,
:post_comments
]
...
has_one :author
has_many :comments
end
I would like to
2010 Mar 24
1
How to stub a has_many relationship in Rails 2.3.5
We have a test that has been working find until we upgraded to rails 2.3.5.
I''m not too familiar with mocks/stubs so maybe there is an easy solution.
Here is a simple example of our scenario.
Class Person < ActiveRecord::Base
has_many :aliases, :dependent => :nullify
before_destroy :mark_aliases_as_deleted
def mark_aliases_as_deleted
self.aliases.each do
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
2006 Apr 14
3
Updateform with a has_many relationship ?
Hello all,
I would like to be able to update the "amount" of a certain item in
me order list.
The problem I run into is how to define the text_field element.
@order is the current order, which has_many :order_item which in turn
belongs_to :order.
order_item has a field "amount" which should be modified...
What I tried is this below, but I get a undefined method
2006 Feb 26
4
Creating objects with has_many :through relationship
Three tables:
users: id
clients: id
admin_contacts: user_id, client_id
class Client
has_many :admin_contacts
has_many :contacts, :through => :admin_contacts, :foreign_key => :user_id,
:class_name => ''User''
end
I added the :contacts for ease of use of grabbing the user objects
associated with the admin_contact.
This all works great, I can grab the Users that
2008 Mar 18
6
Problem with mocking a simple has_many relationship
Hi there all. Sorry if the question sounds silly but i''m rather new at
the ''mocking'' stuff... So here is my problem (code helps more than
talking):
the model:
class Item < ActiveRecord::Base
...
has_many :images, :dependent => :destroy
...
protected
def validate
errors.add(:images, "cannot be empty") if self.images.count
end
end
the
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
2006 May 02
3
Ordering Results returned by has_many relationship.
Noob Question 31,265,232
if I''m searching on an object, say order, that has many "order_lines"
and I want to display order lines by Quantity ( an attribute of the
order_lines ) descending
how could I do that without having to do a find() with :order, but
something like;
Order.order_lines.each do |ol|
<!-- code to diplay the line -->
how can I determine the field
2011 Aug 12
1
Getting nil value when setting an on Join model via a has_many :through relationship
Hi All,
I''ve been trying to figure out what''s wrong here for a little over a
day and figured i''d reach out to the ROR list.
A pastie explains the code a bit better than directly in email:
http://pastie.org/private/mvu0zr1xm18bsk6nfbyama
Basically i have an Artist, and he has many Songs through a join model
called Releases. An artist can be "featured" on a