similar to: reflect_on_association method

Displaying 20 results from an estimated 300 matches similar to: "reflect_on_association method"

2006 Feb 25
7
Help with DRY: too much code in my view
I''m a newbie to rails, and really to the whole DRY and MVC thing as well, except where I accidentally fell into things doing it my own way in the past. I''ve got a fairly complex DB structure I want to create an interface for using Rails. Getting simple tables to display, edit, save, not too much problem there. But where I''m having trouble is figuring out where to
2006 Apr 19
2
Using Reflections to find out ActiveRecord class association
I want to find out what are the associations with another active record class. So If my class is as below: Class Component < ActiveRecord::Base has_many :branches end class Branch < ActiveRecord::Base belongs_to :component end and then I do Component.reflections[:branches].active_record I would expect that to be Branch but it is in fact Component. The inspection of
2007 Aug 10
1
How to spec a model method
Still new to Specs... How do I create a spec to test a model method? Specifically, here is my spec: #testing model describe User do it "should have many user roles" do User.reflect_on_association(:user_roles).should_not be_nil end it "should have many roles though user roles" do User.reflect_on_association(:roles).should_not be_nil end it "should know
2006 Jun 13
6
Dead horse: validates_associated
Regarding validates_associated... Let''s say I have: article belongs_to author But for whatever reason, I want an article to also be written anonymously and therefore not require an author. Then I have: Article: belongs_to :author validates_associated :author But I DON''T have validates_presence_of. What I want to do is validate that an author is valid --if it is
2009 Jan 04
3
Table associated problem using belongs_to
I have two tables: Table [packages] id name user_name ------------------- 1 PK1 Ray ------------------- Table [users] id name full_name ------------------- 2 Ray Ray Sun ------------------- My purpose is to find the full name when I find packages. So I modify Model Package to: class Package < ActiveRecord::Base belongs_to :user, :class_name => "User",
2010 Apr 19
1
Problem with mongrel_rails, but works with script/server
On Mon, Apr 19, 2010 at 9:21 AM, <rpavesic at gmail.com> wrote: > Hi there, I am having problem with mongrel_rails and > I do not know whom to ask so I found your e-mail as > one of the last people contributing to mongrel_rails, so > may be you would be able to help me out. > Please, email mongrel-users mailing list for problems, so in that way all benefit from the answers.
2007 Jul 24
11
Mock or Stub strategy for validates_uniqueness_of
Hi, I''m a bit stuck with mocking a unit test of a join model with regards to a validates_uniqueness_of clause. I have class Book < AR:B has_many :clippings various validates_presence_of etc end class Clip < AR:B has_many :clippings various validates_presence_of etc end class Clipping < AR:B belongs_to :book belongs_to :clip validates_uniqueness_of :clip_id,
2006 Feb 21
3
HABTM :insert_sql help
Hi all, I''m working with a legacy sqlserver db and I''m trying to override the insert sql in as defined in the HABTM method below(becasue the join has three primary keys), but I''m getting the error: ''undefined local variable or method `record'' for Project:Class'' has_and_belongs_to_many :people, :class => ''Person'',
2007 Sep 06
4
HABTM association with own class?
If I have a class, Asset, which has and belongs to many associated Asset objects, how do I do this? has_and_belongs_to_many :associated_assets, :class => "Asset", :foreign_key => ?????, :association_foreign_key => ????? Right now, my table has a :first_asset_id and a :second_asset_id, but I don''t see how the objects themselves are supposed to distinguish one from the
2008 Sep 01
2
HABTM Question
OK, I''m working on a simple site to share music created by users from a forum I belong to. I''m trying to make it so users can follow other users to keep track of what they''re up to (sort of like Twitter if you know how that works). Currently I''m working on the page that displays the users that follow a certain user, I can easily do the reverse of this (see what
2011 May 11
2
Issue with Arel::SelectManager and insert Method
Hello, Arel::SelectManager (arel 2.0.9) uses following statement to insert a new record: @engine.connection.insert im.to_sql, ''AREL'', primary_key_name, primary_key_value But in DatabaseStatements insert ist defined as: insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) Actually, Arel::SelectManager does not use the sequence name. This leads to issues
2008 May 07
1
Assigning to the foreign key on a belongs_to association
I''ve encountered what seems like an odd omission in the behaviour of belongs_to associations: if you assign to the foreign key attribute, it doesn''t update the associated object (or mark a previously loaded one as stale) until you explicitly save or reload it. Let''s say we have a Company model, which belongs_to :city : >> torchbox =
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
2007 Mar 18
7
How to get more informations about an association at runtime
Hi all I''m working on a Custom Formbuilder. I want it to create me with a single method call checkboxes for a given HABTM association. My model looks like this: [code=ruby]class Member < ActiveRecord::Base has_and_belongs_to_many :preferred_music_styles, :class_name => ''MusicStyle'', :join_table =>
2005 Mar 08
15
Rails 0.10.1and WEBrick
Doesn''t appear to work with WEBrick. Works find with Apache/FastCGI. Something wrong in the way Rails is trying to process paths from the WEBrick server. If I try to send in http://localhost:3000/recipes/new, WEBrick is interpreting /new as my controller, instead of my action.
2007 Jul 26
1
Bi-directional self-referential HABTM
Hi, I''m having a little trouble figuring out how to make a self- referential HABTM bi-directional. I have a Employee class. Each employee can have a couple of bosses, who are also employees. The employee class has the following HABTM: has_and_belongs_to_many :bosses, :class_name => "Employee", :join_table => "bosses_courses", :association_foreign_key =>
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
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 Mar 15
3
Self-referential join model does not work
I have been trying to model a labeled graph using ActiveRecord (trunk version). Basically, I have a ''Node'' model which represents a node linking to other nodes. Links (aka edges) are labeled (i.e., have a ''label'' attribute and other behavior). Thus I decided to model edges as an ''Edge'' model and use a ''has_many :trough''
2007 May 23
10
Modifying Conditions for has_many at runtime in controller?
I am attempting to bring Rails into my company, and so far I have been able to impress the senior managers with the flexibility / configurability of Rails on ActiveScaffold. I have hit a point now where I am stumped, and would really appreciate the help of the community. I have a Person ActiveRecord model that has_many Orders. class Person < ActiveRecord::Base has_many :orders end I am