Displaying 20 results from an estimated 10000 matches similar to: "HABTM SQL generated"
2006 Mar 05
8
Model Inheritance, Mixins and Database design
I''m trying to understand how best to use inheritance and wonder if
Rail''s Single Table Inheritance model too restricting.
I have a model Companies who provide 1+ Services (HABTM relationship).
I assume the best way to represent this is with a series of child models
representing each type of service : ServiceType < Company.
I want to return lists of companys for each
2005 Dec 15
2
HABTM being tricky
I''ve just been bodyslammed by a problem with has_and_belongs_to_many -
as far as I can tell, if it doesn''t appear at the top of other
relationship definitions it doesn''t seem to work right. For example:
class Artist < ActiveRecord::Base
has_and_belongs_to_many :genres
has_many :albums
has_many :videos
has_many :cds
has_many :collections
end
..works fine
2006 Jun 10
3
Weird Problem With Active Record
Is it me or is my model getting the created_at from the wrong model!
I have a HABTM relationship between Problems and Tags. In one of my
controller I do the following:
def view
@tag = Tag.find_by_name @params[:id]
end
In my view I do this:
<% @tag.problems.each do |problem| %>
...
<%= problem.created_at %>
...
<% end %>
Now, how come the created_at
2006 Apr 21
1
HABTM - two lists
Does anyone know of a good example somewhere of an implemention for
adding records with HABTM relations that have lots of possibilities.
The best way that I''ve seen it done is where you have two lists
(multiple select lists) where you have the possibilities on the left and
ones you''ve added on the right with arrows to add and delete items. But
the only ways I know how to
2006 Jan 02
5
DB Modelling the Rails way - Opinions??
Hi,
I''m trying to figure the most efficient way to model the following. I
can think of at least two ways to relate the tables but from a
client/server perspective! I''m wondering how to best (and
elegantly)relate them from an AR perspective.
A project has many people,
A person can work on many projects at any time,
A project has many roles,
A role is performed by a person,
A
2006 Dec 29
4
Strange HABTM behavior against SQL Server (AR 1.14.4)
All,
Win XP
SQL Server 2000
Rails 1.1.6 (AR 1.14.4)
I have two objects (Job and Warning) in a HABTM relationship. Below are
the pertinent sections of the model files and the schema for the join
table.
job.rb:
class Job < ActiveRecord::Base
has_and_belongs_to_many :warnings, :foreign_key =>
''JobReferenceNumber''
set_table_name :JobData
set_primary_key
2006 Jan 19
0
Help with nested HABTM relationship
Hi,
I am trying to perform a query with ActiveRecord that I want to put into
a Rails application later. For now I just wrote it within a plain old
Ruby script for easier testing.
I am working with an existing database so I had to map some foreign keys
myself. As you can see from the models below, the database has a
structure of
Prospectlists <=habtm=> Contacts <=habtm=> Accounts
2006 Apr 05
4
Self-referential join creation/deletion and :through
Greetings.
First, this example is just my way of exploring :through. It probably
doesn''t need has_many :through, and could just use a standard HABTM
association.
Here''s the models:
class CourseRequisite < ActiveRecord::Base
belongs_to :requisite, :class_name => ''Course'', :foreign_key =>
''requisite_id''
belongs_to :course,
2005 Nov 16
1
HABTM: deleting records based on attributes
Hello All,
I am new to ROR, and can''t seem to get HABTM to cooperate entirely...
however I might be abusing it! Before I try a different strategy I
thought I''d ask here and see if I''m missing something simple.
So say Projects and Companies are related. Projects can have multiple
Companies, and Companies can be on multiple Projects. But, the same
Company can also
2006 Jul 07
3
Newbie Model question (HABTM?)
All,
If I have a table that has several discrete fields that all point to
the same associated field, how do I model it.
Specifically,
If I have a project table that has 2 fields: specifying_company, and
responsible_company.
And one table of associated companies, how do I do the :belongs_to /
:has_many stuff
ie. For a given project company A may be writing the spec, but company
B may be paying
2007 Jun 23
3
has_and_belongs_to_many and dynamic find
Hi
Just curious if anyone can explain why using a dynamic find fails to
work with << operator
I have standard habtm relationship
class User < ActiveRecord::Base
has_and_belongs_to_many :roles
Now when I assign a Role via << after saving the new User I get wierd
behaviour
but only when using the dynamic version of find
i.e
@user = User.new(p)
if @user.save
#
2006 Jan 09
4
Problem with habtm and resulting SQL insert
Cheers,
I have a problem with 1.0 and a habtm relationship between User and Article.
I want to save all articles that users read. I have these models:
class User < ActiveRecord::Base
has_and_belongs_to_many :read_articles, :class_name => "Article",
:join_table => "read_articles"
...
end
class Article < ActiveRecord::Base
has_and_belongs_to_many :readers,
2006 Jun 10
0
Ordering Based on created_at in HABTM relationship
I have the following line in my controller:
@tag = Tag.find_by_name @params[:id]
Now, how do I order the rows based on the HABTM relationship
problems_tags i.e. problems_tags.created_at DESC
Thanks :-)
John Kopanas
http://www.kopanas.com
============================================================
http://www.soen.info - Index of online software engineering knowledge
http://www.cusec.net -
2006 Feb 13
5
Acts_as_taggable pluralize
I am implementing a messaging system, which requires broadcast to group
feature.
Instead of a relatively clunky habtm group structure, I am using tags.
Form a usability standpoint, it would be helpful to avoid redundant
tags. Like, friend vs friends OR client vs. clients.
Is it practical to filter tags, before entry, to avoid duplicate tags
like plural vs. singular?
--
Posted via
2006 May 30
3
extra attributes in habtm
Hi,
Posting here since issue tracking isn''t the best place to discuss.
I can understand habtm is moving towards deprecating support for extra
attributes in join_table, and to use :through for those cases instead.
To clarify, patch<http://dev.rubyonrails.org/attachment/ticket/5216/habtm_join_table_test.patch1.diff>for
#5216 <http://dev.rubyonrails.org/ticket/5216>
2006 May 24
2
"Stack Level Too Deep" issue in HABTM Unit / Functional Test
Hello guys. I was able to figure out that my "stack level too deep"
error I was getting with my HABTM destroy method was the result of a bug
in rails 1.0. I upgraded to 1.1.2 and now the views and any console-run
commands for destroying AR objects linked together via HABTM work just
fine.
I have HABTM setup between stories and submissions.
The issue is that the destroy methods in
2006 Jun 05
7
Is HABTM Dying?
For a while, I''ve been getting that HMT is replacing HABTM. It appears that
HMT can do all of what HABTM can do and more. The question is: Should I stop
using HABTM? Let''s take a simple case:
A case has many categories
For a given category, there are certain valid statuses
Category
has_and_belongs_to_many :statuses
Status
has_and_belongs_to_many :categories
Question:
Is
2006 Mar 02
3
Modifying "Find" to always add a condition?
I''d like to always add a condition to any version of "find" (e.g.
Thing.find(), Thing.find_by_name(), Thing.find_by_whatever) so that in
addition to whatever conditions are set, an additional condition is set
:conditions=>"user_id=#{current_user.id}"
I''d like to make sure that a user only sees/edits/creates entries in the
database that have the user_id
2005 Dec 29
4
Many-to-Many: Where to add the children?
I have two classes Person and Job defined as follows:
class Person < ActiveRecord::Base
:has_and_belongs_to_many jobs
def add_job(job_name)
job = Job.find_by_name(job_name) # See if this job exists
if job.nil? # If this job doesn''t exist
job = Job.new # Create a new job
job.name = job_name #
2006 Jun 09
2
Creating An Extra Association Between Two Tables
Good Friday Everyone :-).
These are my models:
Problem -> has_and_belongs_to_many :tags
Tag -> has_and_belongs_to_many :problems
Now if a tag does not exist and I create it and associate it to the
problem it works
self.tags << Tag.create(:name => tag)
But if I have the tag already in the DB and just want to link it to
another problem it does not really like me. I do it