In Rails 2.2.2 (ruby 1.8.7-p72), I'd like to evaluate the impact of destroying an object before actually doing it. I.e. I would like to be able to generate a list of all objects that will be affected by :dependent => :destroy (via an object's associations). The real problem I'm trying to solve is to give a user a list of everything tha...
OUR PROBLEM:
If the user which sould be notified is in the requested List ("users")
it's Address Association is initialized with the query provided above.
If we call the NotifyUser-Method the Address Association should be initalized
with all Addresses of the user, but in this case the Address-Association
is cached, and we only get the A...
I have set .jpg file associated to my own program. I want to add the context menu to .jpg files, so I set the entry of HKCR.jpg\shell\open\command to "myProg.exe %1". After associating, there will be an item on the top of the context menu saying "Open image with myprog". This works right when I select a single .jpg file, but when I selec...
I am building a rails site and am having trouble with the associations. Basically I have the following:
class Publication < ActiveRecord::Base
belongs_to :category
has_one :site, :through => :category
named_scope :on_site, lambda {|s| {:include => [:site], :conditions => ['sites.slug != ?', 's']}}
end
class Category
be...
I'm working with models analogous to the following:
class Owner < ActiveRecord::Base
has_many :owned
end
class Owned < ActiveRecord::Base
belongs_to :owner
end
You can presume that owned_id and owner_id are in the right places. The trouble is that, in a controller for a different mvc chain in the app,
@owner = Owned.find_by_id(...
I'm trying to get my head around nested associations in Rails using ActiveResource.
My example is as follows:
What I have is an airport with many runways.
My show action in airports controller contains:
@airport = Airport.find(params[:id])
When I call http://localhost/airports/2.xml I get that piece of XML:
<airport>
<code>DUS</...
Is it possible to list all the applications on a machine that can open a specific file type, using only the files extension? for example if I have a text file (.txt), I want a list of all applications that can open .txt files.
...
I'm using Hibernate 3.2, and using criteria to build a query. I'd like to add and "order by" for a many-to-one association, but I don't see how that can be done.
The Hibernate query would end up looking like this, I guess:
select t1.a, t1.b, t1.c, t2.dd, t2.ee
from t1
inner join t2 on t1.a = t2.aa
order by t2.dd <-- need to add this
...
Hi
I am very new to rails and am having a problem with routing when using polymorphic associations.
On I have a link "Add Comment" on the page installations/1/onposts/2 the link then goes to onposts/2/comments, this works and you can add a comment on this page, when you submit it just redirects to stay on the same page. I want to have a...
A bit of a newbie question on rails associations.
I have a Bug model, and a Status model. Status is basically just a key/value pair table. Out of the choices available, I would say Bug has_one Status makes the most sense. However, according to this
Content belongs_to ContentTemplate. Go
back and look at how I described the
probl...
[Edit: Apparently, this is only an issue for arrays and FoxyBOA's answer might direct to (or even is) the answer.]
Hi, my question relates to these software: Hibernate3+Annotation, Spring MVC, MySQL and in this example also Spring Security.
I was wondering, why collections, which are automatically associated by Hibernate contain null v...
In Rails 2.2.2
In my model I have this:
class Question < ActiveRecord::Base
set_table_name "t346128_question"
set_primary_key "question_id"
has_many :sections, :order => 'position, section_id', :dependent => :destroy
...
end
And in my controller, this:
def answer()
@question = Question.find(params[:id])
puts "question=#...
What's the simplest way to associate my application with a file-extension that works for both Vista and previous versions of Windows ?
Does anyone have an example ?
...
If Parent has_many :children, must Child :belongs_to :parent?
...
If you have
Parent
has_many :children
Child
Is there any reason a foreign key on Child (to Parent) and a corresponding belongs_to :parent might not be desirable?
When, if ever, would you not want your Child to be able to access its parent?
...
I'm trying to get to grips with EF this week and I'm going ok so far but I've just hit my first major snag. I have a table of items and a table of categories. Each item can be 'tagged' with many categories so I created a link table. Two columns, one the primary ID of the item, the other the primary ID of the category. I added some data m...
I have multiple classes with many associations linking them together and I would like to be able to take the top-level object, close it, and have all of the child-objects closed as well. I need each object to be closed because I want to be able to pick any parent and have all of it's children closed.
For example (I realize this probably...
How do I turn this into a has_one association?
(Possibly has_one + a named scope for size.)
class User < ActiveRecord::Base
has_many :assets, :foreign_key => 'creator_id'
def avatar_asset size = :thumb
# The LIKE is because it might be a .jpg, .png, or .gif.
# More efficient methods that can handle that are OK. ;)
se...
Hi,
I'm using the TPH (Table per Hierarchy) technique to map a set of entities.
DB Schema:
UserGroupLabelSpreads table having a "UserId", "GroupId" and "LabelId" nullable fields with some additional common fields.
DAL Objects:
- UserGroupLabelSpread abstract class.
- UserSpread with a discriminator having only non-null UserId.
- GroupS...
Spent a working day on this.
I have
class Box
has_many :users, :through => :subscriptions
end
I also have custom insert_new_users and associate_with(new_users) methods which use multiple INSERT to do their job quickly. Anyway, they work fine. I also have this line at the end of "associate_with" method:
def associate_with
# mysql...