similar to: ActiveRecord Associations issue

Displaying 20 results from an estimated 2000 matches similar to: "ActiveRecord Associations issue"

2009 Jun 02
9
XML::LibXML::Reader
is there anybody who knows how we can get child values using libxml (Reader class) def xml_import_to_brands require''xml'' reader = XML::Reader.file(''c:/brands.xml'') . . .
2006 Aug 09
1
Migrating a Field to External Model
I have a model Product with an attribute ''brand''. Currently it is a simple attribute, however, I am migrating it to a separate model Brand so that I can have other attributes with each brand. I created the the model and created and ran the migration to create the new table. So far so good. Then I created a separate migration to transfer the data. The up method
2006 Mar 22
3
Parent-Child Tables Help
can someone help me with this i have a table cars ( id int model_id int make_id int color_id int description text constraint fk_cars_carmake foreign key(make_id) references carmakes(id), constraint fk_cars_carmodel foreign key(model_id) references carmodels(id), constraint fk_cars_color foreign key(color_id) references colors(id) ) carmakes ( id int carmake varchar ) carmodels ( id
2012 Mar 28
1
collection_select
_form.html.haml = f.label :Select_Brand, "Select_Brand<em>*</em>".html_safe = collection_select(:brand_name, :brand_id, Brand.all, :id, :name, :prompt => "Select a Brand" ) show.html.haml file %table %tr %td Brand_Name : %td = @message.brand_id After writing this code I am not able to see the brand name. Its not giving any error but
2007 May 30
2
newb trying to figure out ActiveRecord relationships
3 tables. item, brand, commercial item -------- id name brand_id name brand --------- id name commercial ---------- id item_id The idea is that a commercial will have one item. each item will have brand. and a brand may have zero to many items. I can''t figure out how to make the relationships for my models. Eventually, i''d like to be able to show a brand name from a
2006 Feb 15
3
Like Query Across Multiple Tables
Firstly, I''m still learning Ruby and rails, so there could be a very simple solution to this. I want to search across multiple tables with a "like" query eg: (SQL is probably the easiest way to describe it): select products.* from products inner join brands on products.brand_id = brands.id where products.name like ''%canon%'' or brands.name like
2009 Jul 23
11
Problem with named_scope
Here are my scopes: default_scope :order => ''posted_on DESC'', :conditions => { :status => ''visible'' } named_scope :positive, :conditions => { :rating => ''positive'', :status => ''visible'' } named_scope :neutral, :conditions => { :rating => ''neutral'', :status =>
2006 Sep 28
15
Inserting rows into linking table
Hi, I have two objects: Contacts Lists I want to be able to add multiple contacts to multiple lists. I''ve created a linking table and a form that allows me to select the contacts using checkboxes, but I''m having some problems with the controller and model. I receive the following error message when I submit the form: Mysql::Error: Cannot add or update a child row: a
2010 Jun 17
1
Problem with options_for_select
Hi, I have a problem with the form select. In the value field I have the generated html... <%= f.select :brand_id, options_for_select([[''Brands'', 0]] + @search_brands.map { |b| [b.name, b.id]}), {:id => ''cbxBrand'', :tabindex => (@tabindex += 1)} %> This is the html: <select name="search[brand_id]"
2011 Feb 17
1
Select distinict on not chainable with order method
Hi. I would like to do code refactoring: @beers = [] Beer.all.each do |beer| unless @beers.find{|c| c.brand_id == beer.brand_id} @beers << beer end break if @beers.size > 29 end So I achieved this by writing scope (on PostgreSQL): scope :with_unique_brand, select("DISTINCT ON (beers.brand_id) beers.*") Using this scope alone is working
2006 Apr 12
0
fixtures advanced question
Hello, in my database i have tables models,marques,cars. I wrote fixtures for models f1: id: 1 marque_id: 1 name: 100 NX f2: id: 2 marque_id: 1 name: 200 SX f3: id: 3 marque_id: 1 name: Almera f4: id: 4 marque_id: 1 name: Patrol f5: id: 5 marque_id: 1 name: Primera f6: id: 6 marque_id: 2 name: CLK f7: id: 7 marque_id: 2 name: CLS f8: id: 8 marque_id:
2006 Mar 06
5
Question about file_column plugin
Hi! File_column plugin saves uploaded files to "public/model/image/model_id/filename", if i understand it correctly. Does it mean that it creates new folder for every image? I have product (model) that has_many images (model). Is it possible to use (or modify) this plugin that it would save my images to different folder, so the id of the model_id part would be id of the product
2007 Sep 19
3
Create method calling wrong column name in a table
I have a multitable database with an observer logging changes into a datachange table. The create method inserts the data into the data change table, updates my model, and then trys to load from the datachange table. When it does this it WHERE clause that is generated for me is looking for a column model_id which I dont have. I don''t want to even have a field because this table will be
2009 Apr 24
1
RoR - getting started with database relations
Hey everyone... I''m just getting my feet wet with relational databases using RoR models. The software I''m putting together relies on car parts. Originally I had the database set up as follows create_table :parts do |t| t.column :year, :string t.column :make, :string t.column :model, :string . . . end However, I now realize it''s much better to do it using
2006 Jun 30
0
Interpolation in association conditions broken; broken backwards-compatibility?
I believe it used to be possible to interpolate values into associations'' conditions with single quotes, but it isn''t anymore. has_many :widgets, :conditions => ''brand_id = #{brand_id}'' Anyone else remember that? It seems to have been snuffed out in changeset 3897 with the removal of interpolate_sql(@conditions) Was the change (and the fact that it
2006 Nov 26
0
concatenate fields in collection_select
Hi, I am filling a collection_select with a list of models references based on a column named "model_ref". <%= collection_select(:assets, :model_id, @models, :id, :model_ref,:prompt => ''- Select a model -'') %></p> I have two issues : 1) I would like to concatenate another column next to the model reference inside the option value with the description
2006 Jul 19
5
weird result for a custom attr reader!
Hi all, I am having a weird problem reading a value from my model. basicaly, I have these two models: class Category < ActiveRecord::Base acts_as_tree :order => "name" belongs_to :item_type has_many :specific_category_names end and class SpecificCategoryName < ActiveRecord::Base set_table_name "Specific_category_names" has_many :products belongs_to
2008 Jan 13
2
module_eval and scope question
When trying to understand a piece of code from the Ruby-On-Rails framework, I found that I''m still lacking knowledge about scope issues in Ruby. Here is a stripped down version of the code I''m trying to understand (in case you happen to use Rails: This is from file scaffolding.rb): module ActionController module Scaffolding .. module ClassMethods def
2006 Nov 29
5
Collection_select with two columns and a prompt
Hello, I am quite a newbie to RoR, I hope you maybe able to help. I have a collection_select in a _form.rhtml: "collection_select(:assets, :model_id, @models, :id, :model_ref,options={:prompt => ''- Select a model -''})" As you see my drop down menu will show the model_ref column. 1) Is it possible to have more than one column. For example I would like to
2005 Nov 30
8
nested attributes with update_attributes()
Hi, I am trying to use the update_attributes on object with nested attributes and I am getting the following error: ProductPrice expected, got HashWithIndifferentAccess Here''s the situation (simplified): class Product < ActiveRecord::Base belongs_to :productPrice end class ProductPrice < ActiveRecord::Base has_one :product, :dependent => true