Given Ryan Bates's great tutorial on Virtual Attributes, how would I go about destroying a Tag (not Tagging) if, once the article is destroyed, that Tag is no longer used?
I tried doing something like this:
class Article < ActiveRecord::Base
...
after_destroy :remove_orphaned_tags
private
def remove_orphaned_tags
tag...
Hi. I wondered if someone could take a quick look at this. I'm making a simple conversion application which converts between units of measurement. I need to be able to self reference the table using a join table which stores the relationship between each, along with the conversion between each. This then would be referenced between eithe...
This is probably quite simple but I haven't yet been able to wrap my head around the problem.
I have 3 tables... (well more than that) but in this scenario 3 that matter.
Places
Bookings and
Ratings
Places has_many bookings
Each booking has_one rating (because the user only rates once) and belongs_to (a) Place
Ratings belong_to (a) ...
Hi There,
I have a pretty basic association:
# user.rb
class User < ActiveRecord::Base
has_many :services, :through => :subscriptions
has_many :subscriptions, :accessible => true
accepts_nested_attributes_for :subscriptions
end
# service.rb
class Service < ActiveRecord::Base
has_many :users, :through => :subscriptions
has_ma...
Using has_many => through association.
Here is what i have.
:planning model
has_many :acttypes
has_many :actcategories
has_many :acts, :through => :actcategories
:acts model
belongs_to :acttype
has_many :actcategories
has_many :plannings, :through => :actcategories
:actcategories model
named_scope :theacts, lambda { |my_id|
...
I have a problem with associations. As a newbie to RoR, I've learned about associations from the guide on the RoR site. I have followed one of the example almost to the letter, the only thing being changed are the class names. The example being the following:
class Document < ActiveRecord::Base
has_many :sections
has_many :pa...
I have such angry associations: financings >- events >- subprograms >- programs. I want to get acces to last_financings from programs through all of them so code is:
class Fcp < Program
has_many :fcp_subprograms,
:foreign_key => 'parent_id'
has_many :subprogram_last_actual_financings,
:through => :fcp_subprogra...
I'm coming across a problem that I can't find much online for via Google, forums, groups, etc. and so I'm going to raise my hand and ask for help from those who are more wise than I :)
I have a rails project setup that was using nested_attributes_for with a one-to-one relationship between two models. It worked quite easily and as expec...
I have a has_many :through relationship associating players to teams THROUGH managements.
I want to have a counter on the teams table (a bit like a counter cache) that tells me how many new associations there have been since the beginning of the week. Of course a counter cache wont work because it will always give all the associations t...
I have the following three models: User, Project, and Assignment.
A User has_many Projects through an assignment. However, Assignment actually has two foreign keys that relate to a User: user_id (representing the user who was assigned the project) and completer_id (representing the user who completed the project).
Often, user_id and co...
While I'm not a complete Ruby/Rails newb, I'm still pretty green and I'm trying to figure out how to structure some model relationships. The simplest example I can think of is the idea of "recipes" for cooking.
A recipe consists of one or more ingredients and the associated quantity of each ingredient. Assume we have a master list in th...
I have an invoicing system that manages debits and credits. Basically the invoice amount is obtained by the sum of its debits and the balance is derived by taking the sum of its credits and subtracting it against the total amount.
I'm doing this with four models.
Invoice
Line Item
Debit
Credit
The way it works is via a join model (L...
I've created an application that finds service providers based on multiple services passed to it. This is done via has many_through so there is a join object. Basically, if a user asks for service providers with Service A and Service B my scope returns service providers who offer either BOTH Service A and Service B or other service provi...
I have 4 models: transac, transac_data, item, dvd_details
class Transac < ActiveRecord::Base
has_many :transac_datas
has_many :items, :through => :transaction_datas
end
class TransactionData < ActiveRecord::Base
belongs_to :item
belongs_to :transaction
end
class Item < ActiveRecord::Base
has_many :transaction_datas
has...
I have the following models in which I join the Language and Products table via the Translation table using the Rails has_many :through paradigm:
class Language < ActiveRecord::Base
has_many :translations
has_many :products, :through => :translations
end
class Translation < ActiveRecord::Base
belongs_to :product
belongs_to :lan...
I have a User Model(:name, :password, :email), and Event model(:name, :etc) and Interest model (:name) [>all singular<]
Then I created two join tables -> UsersInterests and EventsInterests; each not containing a primary key and only comprised of the user_id/interest_id and event_id/interest_id respectively. [>plural<]
My Models Use the...
I have a User Model(:name, :password, :email), and Event model(:name, :etc) and Interest model (:name)
Then I created two join tables -> UsersInterests and EventsInterests; each not containing a primary key and only comprised of the user_id/interest_id and event_id/interest_id respectively.
I'm trying to use ActiveRecord to query a lis...
I searched and tried a lot, but I can't accomplish it as I want.. so here's my problem.
class Moving < ActiveRecord::Base
has_many :movingresources, :dependent => :destroy
has_many :resources, :through => :movingresources
end
class Movingresource < ActiveRecord::Base
belongs_to :moving
belongs_to :resource
end
class Resource <...
This is my model:
class Tag < ActiveRecord::Base
# id, name
has_many :taggings
end
class Tagging < ActiveRecord::Base
# id, tag_id, owner_id, target_type, target_id
belongs_to :tag
belongs_to :owner, :class_name => 'User'
belongs_to :target, :polymorphic => true
validates_uniqueness_of :tag_id, :scope => [ :target_id, :ta...
Given the following AR models, I would like to sort users alphabetically by last name when given a handle to a task:
#user
has_many :assignments
has_many :tasks, :through => :assignments
#assignment
belongs_to :task
belongs_to :user
#task
has_many :assignments
has_many :users, :through => :assignments
I would like to get a task ...