similar to: has_many, conditions overrride

Displaying 20 results from an estimated 11000 matches similar to: "has_many, conditions overrride"

2007 Jan 31
2
has_many :conditions
Is it possible to put conditions relative to the current instance in has_many''s :conditions? For example, in a forum app: class Post < ActiveRecord::Base belongs_to :topic has_many :self_and_descendants, :class_name => "Post", :order => "lft", :conditions => "topic_id = #{topic_id} AND (lft BETWEEN #{lft} AND #{rgt})" end With the
2009 Oct 31
1
How to changing a AASM state using a Edit Action+Form View?
Hello there, I''m using AASM to manage states in my User model. I want to change the status through the edit action. To do this I''m using the method User.aasm_states_for_select in my form to populate the select input for states. When I hit the button commit all the changes are saved, including the state name. But the AASM event for that state is not called, it is happening
2010 Jul 15
3
aasm manage states
Is there a way to manage the states in AASM by keeping them in a table to normalize the data? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to
2009 Mar 03
2
Looks like a bug - Ruby1.9.1Rails2.3.0 - script/plugin
I started talking this one up yesterday - I''ve gotten as close to a good problem statement as I can. 1) script/about: Ruby version 1.9.1 (powerpc-darwin9.6.0) RubyGems version 1.3.1 Rails version 2.3.0 Active Record version 2.3.0 Action Pack version 2.3.0 Active Resource version 2.3.0 Action Mailer version 2.3.0 Active Support version
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
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:
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 Jan 19
2
has_many :through
Has anyone had much experience using the new has_many :though options that are currently in Edge Rails? I''m looking at using it in my project but haven''t found much about it. Kyle
2006 Aug 03
12
More than one has_many :through association between the same 2 models
I wonder if you can have more than one has_many :through association between 2 models. For example... I have a model Teacher and a model Class Now, 1 Teacher works in many Classes, right?. So I need a join model like class Work < ActiveRecord::Base belongs_to :teacher belongs_to :class end But I also would like to know if a teacher CAN teach a class before I
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 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
2007 Feb 05
6
Viewing object associated via "has_many :through"?
This is my first question to the Forum. I’ve 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 May 23
7
self-referencing has_many
Having a devil of a time finding records in a self-referencing has_many table relationship. Everything is working find looking at the has_many and the belongs_to relationship. But, when I try to find all "orphans", records that are neither a parent nor a child, I can not find a query that work in ActiveRecord. This query works in MySQL: SELECT * FROM templates LEFT JOIN templates
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
2010 May 31
2
has_many and has_and_belongs_to conflit
Hi, I have 2 models: User and Article. I have this relationship: * User has many articles (and Article belongs to user) * User has and belongs to many articles (and Article habtm users) But this is tricky because of: current_user.articles ...this can return articles thanks to *has_many* and *has_and_belongs_to* relations. So there''s a collision. How can I ask articles thanks
2008 Dec 13
3
how to do "special queries" ala The Rails Way on "associated" conditions?
I have the following in a model class: class Game < ActiveRecord::Base has_many :player_stats has_many :players, :through => :player_stats def visitor_stats stats = [] player_stats.each do |stat| stats << stat if stat.player.team.team_code == self.visiting_team_code end stats end def home_stats stats = [] player_stats.each do |stat| stats << stat if
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