Displaying 20 results from an estimated 10000 matches similar to: "Avoiding adding duplicates to has_many collection?"
2006 Apr 09
1
select helper question
Hi there, I try to develop a medical application using ruby on rails.
There are many categories which can contain subcategories.
I defined the model like this:
class Category < ActiveRecord::Base
has_and_belongs_to_many :notes
belongs_to :parent_category, :class_name=>"Category",
:foreign_key=>"category_id"
has_many :sub_categories,
2006 Jan 02
6
Paginate with joins messing with id
Hi all,
Best wishes for the new year! :'')
I''m very new to Ruby and Rails, and I ran into a problem with the
"paginate" function. When I use the following method to get a number
of forum topics based on a category name passed via the URI:
@topic_pages, @topics = paginate :topics,
:joins => "INNER JOIN categories ON
2013 Nov 10
3
accepts_nested_attributes_for how, example
I have following tables with following models:
users(id, role_id) *has_many :entries*
categories(id, category_name) *has_many :entries*
entries(id, category_id, user_id) *belongs_to :user, belongs_to
:category, has_one :storage*
storages(id, title, content, entry_id)* belongs_to :entry*, *has_one
:vote*
votes(id, count, storage_id) *belongs_to :storage*
Now,
2006 Jan 08
2
sorting issue
I''ve got the following setup:
category (hm) <-> (bt) activity
An activity has an amount, date, location, note, and category. I''m
sorting my activities table by category_id (foreign key in activity),
but how do I sort it by category_name instead? Basically I just need
category_name in the result set. Here''s what I have now:
@all = Activity.find(:all, :order
2009 Feb 21
3
belongs_to or has_many
2 tables Items and Categories
Categories (id, name)
Items (id, name, category_id)
Category_id can be null, and there are Categories that has not an Item.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email
2006 Aug 12
7
Collection assignment to a has_many :through
I''m working on a simple photo gallery in rails, it seems to be a good
project for a newbie.
I have photos and categories, many-to-many association. It worked well
with HABTM. Then I decided that it would be good to be able to change
order of the photos so that thumbnail pages would look less chaotic.
So I created a Layout model which is a join model (or whatever it is
called) that
2006 Jul 07
0
has_many relation handling
Hello,
please have a look at this:
My tables:
create_table :languages do |t|
t.column :name, :string, :limit => 3
t.column :title, :string, :limit => 30
end
create_table :categories do |t|
t.column :category_id, :integer (3.)
t.column :created_at, :timestamp
t.column :updated_at, :timestamp
end
create_table :categorytranslations, :id
2009 Jun 22
5
has_many through , or habtm , using form
i think there ara two ways of relate products and categories ,
basically i want to fix one product(e.g hp dv7....) to some categories
(notebook,17"notebooks...)
i made a table named categorization(incuding category_id,product_id
fields) then in models i write these codes below
class Product < ActiveRecord::Base
has_many :categories, :through => :categorizations
2011 Aug 17
1
has_many :through, collection<<(object) and duplicates.
Hi,
I''m facing a strange behavior in Rails with the has_many association and
the generated collection<<(object, ...) method that comes along.
I''ve got an Object model and a Tag model, plus a taggings table to join
the two together.
On Object, I set these associations:
has_many :taggings, :as => :taggable, :dependent => :destroy
has_many :tags,
2006 Jul 07
9
Search on data accross many tables, linked by belongs_to
I am using Ferret and acts_as_ferret, as my search back-end for my Rails
project. I have a question about using acts_as_ferret on a main table
that is linked to other tables by foreign keys. Is there a way to
include the information linked by the belongs_to keyword in the search
results ?
As an example, let''s say I have a main table ''posts'':
2014 Apr 06
0
collection_check_boxes with has_many through: association Rails 4
I am trying to list all the categories a user can be interested in with
check boxes so that a user can submit these interests through my join table.
collection_radio_buttons works with a simple has_many, belongs_to
association:
<%= collection_radio_buttons(:listing, :category_id, Category.all, :id,
:name do |b| %>
<%= b.label { b.radio_button} %>
<%= b.text %>
2006 Mar 14
7
Single form w/ relationships: how do I integrate it?
OK - I know this has been asked before, but I cannot find it in the
archives. Forgive me if I''m creating more noise than I should.
I want to know the easiest way to deal with this scenario:
I have articles. I have categories for the articles.
On the form where you write an article, there needs to be a free-form
field to entire the category.
The create() method will build the
2006 May 11
0
Quick question on has_many :thorugh
I was reading the documentation on this today and was wondering more
about the has_many :though, :dependent=>:destroy options. I am curious
how deep the deletes goes. Does it stop with the intermediate table or
does it pass through to the final table?
For example:
database
Categories (name, id)
Listings (category_id,product_id)
Products (id, name)
Assume in my Category Class I have
2005 Nov 11
0
Possible to simplify these routes?
In my routes.rb I have:
map.connect
''items/category/:category_id/order/:order/page/:page'',
:controller=>''item'',
:action=>''list'',
:requirements => {:category_id => /\d+/}
map.connect
''items/category/:category_id/order/:order'',
:controller=>''item'',
2006 Jul 12
1
odd habtm behavior? or is it me?
Hello List,
I''m a bit spent on this problem, and my code might be whack. I seem to be
encountering a problem where the primary key on a join table is not being
resolved correctly. I will elaborate after some code bits. I am creating
the join table using migrations, and relevant model code is this:
class Post < ActiveRecord::Base
has_and_belongs_to_many :records
2006 May 04
2
Building a FAQ
I''m new in Rails, and I''m building my first application. I''m trying to make
a FAQ for this application, organized by product (questions about each
product) and category (questions of different categories or topics), and
there is something I can''t figure it out how to do.
I have these tables:
create_table "faqs" do |t|
t.column "question",
2006 Dec 19
2
Dedupping Has_many through, :unique=>true
Hi, In the Agile book, it is told that by putting a :unique => true will
dedup the row with ActiveRecord.
But it''s not working out for me. Do I need edge rails for this?
I simply want to dedup any join model associations, for instance:
category_id | inventory_id
384 1 first entry
384 2 this would be ok.
384 1 this would
2006 Jan 10
5
Select Tag and Associations
Hi there,
I''ve been working on this for awhile and have finally decided to ask
for a little guidance.I have a slight problem trying to save a
selection.
I have two models:
A "Posting" has_many "Categories", and a "Category" belongs_to one
"Posting". With that said, in the posting model I have "has_many
:categories" and within the
2005 Apr 27
5
Eager load mysteriously deletes records
Hi
This looks like a bug in ActiveRecord.
I am messing with eager loading (on 12.1) and all of a sudden records
started disappearing from a table (and I am not doing anything delete
related)!!
The following line works OK:-
@todos = Todo.find(:all, :include => [ :whens],:order => "position ASC")
The following line is mysteriously deleteing :where rows from the DB
after
2006 Jan 18
2
categories/recipes & books/descriptions - has_many vs has_one => id question
People,
In the cookbook eg, categories has_many recipes but in a book eg, book
has_one description - doesn''t that mean that the id of the description
should be the same as the id of the book (instead of having it''s own
"description_id" in the book table?
Thanks,
Phil.
--
Philip Rhoades
Pricom Pty Limited (ACN 003 252 275 ABN 91 003 252 275)
GPO Box 3411
Sydney