Displaying 20 results from an estimated 90000 matches similar to: "Is there a better way to do this (SQL groups)?"
2006 Jun 08
0
Bad design or better way?
I am at a loss as to whether this page of my site is poorly designed or if
there is a better way to achieve what I am looking for.
My concern lays in one piece of controller code. I really don''t like the
way I have to use params[:answers].values, nor do I like that for the
creation of each response it has to find the answer associated with it. Any
help would be greatly appreciated.
2006 May 12
2
Has many through join table issues
I''m trying to wrap my caffeine soaked brain around has_many :through
following along at:
http://rails.techno-weenie.net/tip/2005/12/23/teaching_your_blog_model_new_tricks_with_has_many_through
I think my models are a little more complex than what fits this
narrative.
I have a directory of members, each member can belong to multiple
categories.
The category table references itself
2006 May 11
6
ActiveRecord associations
Can someone clarify this for me? Suppose I have two tables like:
class Company < ActiveRecord::Base
belongs_to :category
end
class Category < ActiveRecord::Base
has_many :companies
end
I understand that the belongs_to causes related companies to be read
from the db when I ask for a category. I suspect SQL something like
select * from categories, companies
where category.id
2009 Apr 12
0
rails 2.3 nested forms with has_many through checkboxes
I was wondering if anyone knew of a way to combine the new nested
forms in rails 2.3 with a has_many through relationship via
checkboxes. Basically I have a page model, a page_category model and
a category_items join table. Pages have many page categories through
category items. The category_items table is polymorphic so i can use
it for other models who need categories (maybe this is
2006 Jul 04
1
Has_many :through with checkboxes?
Just when I started getting the hang of has_and_belongs_to_many
relationships, I realize that I should probably convert several of my
app''s joins to has_many :through type relationships.
One example, pairing users with categories via subscriptions, where
each user can be the "owner" of a category, has given me particular
trouble when I try to update a user''s
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 May 25
5
Model Structure Advise
Hi,
I''m starting to build a simple (?!) FAQ system, and I''d like some
advice on setting up the model relationships.
I was going to go with a simple system of a Category table and a FAQ
table (holding questions and answers) - where one FAQ belongs to one
category.
That''s all nice - a simple has_many / belongs_to relationship. Then I
decided to add another level - Area.
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
2006 Apr 15
8
Inheritance in Rails - I need some help
I''ve got a model, "category" and another model "subcategory." Each
subcategory belongs_to a category, and a category has_many
subcategories.
What I need to do is set it up so that I can search Category and
Subcategory with one .find call. So:
Category.find(:all, <etc)
will find categories and subcategories.
Now, I believe this can be done by making
2010 Dec 30
3
rake db:seed with has_many through (m:n with seperate table)
My model consists of users and tasks (m:n), the relation is stored in a
seperate table sharedtabs (that contains some extra fields).
Between tabs and tasks there is a 1:n relation.
I have trouble writing my seed.rb:
works: (1)
tab = Tab.create(:name => ''Admin'', :category => 0)
tab.tasks.create(:name => ''Admin_Tab1_Private Task 1'')
works: (2)
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
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
2013 May 27
3
Ransack, acts-as-taggable-on and checkboxes in search form
need some help on ransack filtering.
I have model Project, which has many tags through acts_as_taggable gem.
Project.rb:
class Project < ActiveRecord::Base
include PublicActivity::Common
belongs_to :customer
belongs_to :category
has_many :attachments, :as => :attachable
has_many :reports, :dependent => :destroy
has_many :messages, :dependent
2007 Jun 18
4
polymorphic validation
Hello
I have 2 models.
link.rb
has_many :categories, :as => :categorized
validates_presence_of :name, :url, :created_at, :category
category.rb
belongs_to :categorized, :polymorphic => true
validates_presence_of :name
Everything seems to work. I select my category from a select tag. The
problem is i don''t know how to validate if category is for example empty
(nothing in a
2006 Jun 03
2
Parent listing children.
My database is set up as Categories > Things associated by category_id
and has_many and belongs_to.
How would I go about listing all the categories and under each Category
is it''s children? Is there an easy rails way to do this - preferably
without using acts as tree? Any help is appreciated - thanks!
--
Posted via http://www.ruby-forum.com/.
2006 Jun 28
0
Most recent detail record for master records - what''s the best way to do this?
I''m trying to figure out the best way to display some summary information in
my app (an article submission database for writers), and I''m not quite sure
how to get ActiveRecord to give me what I want.
Here''s what the relevant part of my data model looks like:
-----------------------
class Market < ActiveRecord::Base
has_many :submissions
has_many :articles,
2006 Nov 21
14
Starting from scratch
I have the following models:
===
class Person < ActiveRecord::Base
has_many :person_organisations, :dependent => true
has_many :organisations, :through => :person_organisations
has_many :person_categories, :dependent => true
has_many :categories, :through => :person_categories
end
class Category < ActiveRecord::Base
has_many :person_categories, :dependent => true
2008 Dec 07
1
How to describe self join in a model
Hi ,
I am new to rails, and i need to know one thing, i have a table
called Categories and i want to self join it in such a way , that one
category could be a parent of many categories, but could be child of
only one category.
Please tell me how to tell rails , in my Category Model, does the
following work for me ?
class Category
belongs_to :category
has_many :categories
end
2008 Mar 12
1
Ordering across related tables
I have two related tables: groups and categories. In the models,
Group
has_many "categories"
Category
belongs_to :group
Category does have a column, "group_id" as required.
Both the groups and categories tables have a "sortorder" column which
dictates the order the items are to be presented.
In my controller, I want to retrieve the Categories
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,