search for: belong_to

Displaying 20 results from an estimated 63 matches for "belong_to".

Did you mean: belongs_to
2006 Dec 05
1
has_many :through questions
I have a database with 4 tables Months has_many :weeks Weeks has_many :days Days has_many :hours Hours Weeks belong_to :month Days belong_to :week hours belong_to :day I need to access the month_id in the Hour.rb model. find(:first, :conditions => ["user_id = ? AND month_id = ?", user_id, month_id]) Thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~-...
2006 Apr 20
5
strange mysql problem
...SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' , , , )'' at line 1: INSERT INTO line_items (`qty`, `quote_id`, `price`, `lead_time`, `part_number`) VALUES(, , , , ) why is it doing that? all my other models that belong_to something work.
2012 Jan 27
3
How to test the model dependence ?
...oblem. I need to test if my model "Procedure" is linked to the workflow. If not, the system must acknowledge an error. Below is the code that is in the file test \ unit \ procedure_test.rb. require ''test_helper'' class ProcedureTest < ActiveSupport::TestCase should belong_to :workflow should has_many :tasks, :through => :workflow #should has_one :timeline #should has_many :timeline_items, :through => :timeline end The shoul "belong_to" is working normally but when running "rake test" appears the following error: $ Rake test / home / gu...
2012 Nov 18
3
remarkable activerecord association RSpec
...'ve installed remarkable and remarkable activerecrod both gem. i''ve added both gem in my Gemfile. i''ve added "remarkable_activerecord" as required in spec_helper.rb. describe Authentication do FactoryGirl.build(:authentication).should belong_to(:user) end it "has a valid factory" do FactoryGirl.create(:authentication).should validate_presence_of(:uid) end i got error: : undefined method `belong_to'' and undefined method `validate_presence_of'' what should be done...
2005 Dec 20
3
Single controller to browse things in categories
First off, hi, I''m [obviously] new :O) Please excuse my question as I''m sure it''s been answered, but I can''t find it anywhere. I have a table of categories: id name 1 Foo 2 Bar I have things which belong_to categories: id category_id subject date 1 1 my subject 07/09/2004 and Further classifications which belong_to categories: id category_id name 1 1 More Foo 2 1 Most Foo 3 2 Some Bar and subcategories which belong_to categories, classifications, and things id category_id classification_id thing_id...
2007 Mar 29
21
a better "should have valid associations"
This is pretty much the same as last time around, if you recall. Thanks to Wilson for converting to the new form. I''ve added a few lines. Basically, it iterates over your model associations and does two things. - First, just try to call the association. Usually fixes speeling erors or other such silliness. - Second, try to find a record with an :include on the association. This
2010 Aug 19
4
implementing project management and event types
...n specific to a "get access" event (remote access, username, passwords, etc). Another event type might be "upgrade" which stores information about the server to be upgraded, etc. So I have: * a project which has_many events * events which belongs_to :project * sub-events which belong_to :event How do the subevents relate to event? An event will never have more than one subevent, but it may not have any of a particular subevent. Thanks for your help on this? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To p...
2006 Jun 26
10
Create tables on the fly in rails?
Hello everyone :) Love the mailing list! I read it as much as I can! Thanks all you RoR guru''s for providing so much help. Anyways... So say I have Users, and each user can have a list of Plants that they like. I would want to give each user a table that has many entries to show me which plants they like. How could I do this? I don''t know if there''s a way to do
2006 Mar 30
5
Heeelp - no idea what''s going wrong.
I''m working on a simple CMS. The main data type are "listings" a listing habtm (has_and_belongs_to_many) categories and subcategories. Subcategories belong_to categories. Subcategories are basically the same as categories, but they are treated differently in a few situations. The problem is, I can''t seem to write the view/controller/model code that allows me to create a listing that contains subcategories! Even though I''m using the...
2006 Mar 16
4
Table Relationships Problems.
...39; relationship with systemmessages, meaning that there could be many valid times for each system message. @systemMessage = Systemmessage.find(1) E.g. I can access a system valid time like this : @systemMessage.systemmessage_datetimeranges[0].id I went ahead and made systemmessage_validtimes belong_to locations. But when I try to access the locations variable, it doesn''t exist. The location object isn''t being joined into the return object. I can retireve the location_id, but the following fails : @systemMessage.systemmessage_datetimeranges[0].location.name I did an inspe...
2006 Apr 09
6
Write/Display AR query as Grouped Results?
I''ve got a publications table that contains an author_id foreign key and a pubrole_id foreign key. What I want to do is query the DB using AR so that I can get a list of all publications that belong_to a particular author, and group the results by the pubrole.role_name (Author, Joint Author, Editor, etc.) so that the results look something like: Author book1 info book2 info etc. Joint Author book1 info book2 info Editor etc. Can anyone suggest how to do this, or point to an example...
2006 Mar 08
0
How to add something similar to :counter_cache - :avg_cache
Hi, I was thinking of doing this with a stored procedure, but I thought it could be better implemented in Rails. I have several tables that hold a counter cache for other tables, which aren''t directly related. For example: Table ''schools'' has records that belong_to table ''counties'', and that table has records that belong_to table ''states''. In both states, and counties, there''s a column named ''schools_total''. I don''t use Rails built in counter cache because schools don''t belong d...
2011 Sep 14
1
rspec and should have_many through
Hi, Anyone can help me with rspec shoulda validations please. I can''t get the syntax right for these validations. Please correct me it { should have_one :tradable, :through => :trade_order} it { should belong_to :source, :polymorphic => true } it { should have_many :transfers, :as => :source } this is for Rspec 2, rails 3.1, gem "rspec-rails" gem "remarkable_activerecord", "~> 4.0.0.alpha4" gem ''rspec-rails-ext'' gem ''rspec-ra...
2005 Dec 15
8
How to ensure deletes cascade to associated models?
I have the following models: class Resume belongs_to :resume_assignments end class User belongs_to :resume_assignments end class ResumeAssignment has_one :resume has_one :user end When I delete a resume, I want to make sure that its associated ResumeAssignment gets deleted also. Calling destroy_all to delete some resumes doesn''t seem to do this. Is there an option that will
2006 Feb 28
1
adding to errors in controller?
...end end if @product.errors.empty? and @product.save flash[:notice] = "Product was successfully updated" redirect_to :action => "show", :id => @product else render :action => ''edit'' end end Currently, products belong_to images, but later, I''ll probably have products has_many images. Say an image is invalid. So it won''t be saved. How do I properly show that to the user? The above is my approach, where I have to manually add image.errors.full_messages to the product.errors. But then, I noticed...
2006 Mar 21
2
Sorting by computed temporary field
...all, I''m rather new to Ruby and Rails (and not great with SQL), but I''m developing a ride sharing app and would like to be able to sort on something I don''t have stored. I have users, events, and rides, each of which has a zip code. Events have_many rides, and rides belong_to events. When an event is selected, I''d like to be able to show a list of rides to that event, sorted by distance from the logged-in user. What are some ways to do that? Here''s what I can think of: - Make a new find_and_sort method that adds a new @distance member element and...
2009 Mar 18
1
set_table_name woes, fragmented domain class
...the same table. So I''ve split out the records into many different tables, each with its own suffix which corresponds to the id of the model to which all records in that particular table belong. For example, if I have a Domain AR object with an id of 20, all DomainURL objects that :belong_to that particular Domain object are stored in table domain_urls_20. This necessitates a call to set_table_name before the DomainURL objects are fetched, like so: DomainURL.set_table_name "domain_urls_" + domain.id However, when I go into production mode, I get mismatched table and...
2006 Jul 14
20
Method for associated relationships
I have these tables set up like this: listings has_many :states <field>state_id [int] <other fields.... .............. .............> states belongs_to: listings <field>name <other fields.. ............... .................> In my view I have <%= listing.name %> have also tried listing.state_id.name , that didn''t seem to do the magic either. This
2006 Jan 12
2
Can A Model Have Many belongs_to?
...ems, I have several thousand systems but only 8 or nine operating systems. Any peer review the community can provide would be much appreciated. One last question; I have a table of old hostnames (Oldnames). Oldname belongs to System and System has_many Oldnames. Since system doesn''t belong_to oldnames ,what''s the easiest way to fetch a System''s collection of Oldnames? Thanks for the help! - Don -- Posted via http://www.ruby-forum.com/.
2006 Mar 08
4
Creatulator: Before I go and make it myself, does this exist...
...ot;what is the primary key" "what relation does this foreign key belong to" etc... So what I am about to go and write myself is a database introspector that will look at a database and create all the Models for every table for me, including all the set_primary_key, all the has_many belong_tos, and many, if not all, of the validates_blah based on the database constraints. This is going to be quite an undertaking, so before I go and do it, does anyone know of something that already does this that has been previously written?