Displaying 20 results from an estimated 5000 matches similar to: "Dynamic relation with eager loading"
2006 Apr 24
2
Checkboxes - Saving a Checked record to another table
I am displaying a bunch of records from a table called "assets". Next
to each record i have a checkbox. When this box is checked i want to be
able to save the id of the record into another table called
"flagged_assets". All I need is the ID, nothing else. Im struggling
with the logic to save to another table. I know how to do it if the
asset_id is already in the
2007 Jul 23
2
ActiveRecord.find :group option
I have a very simple find call...
@assets = Asset.find(:all, :group => ''asset_type_id'', :order => "name")
I have 3 Asset objects in my database, all of which have asset_type_id
equal to 1. Why does this query only return 1 object?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because
2011 Jun 04
0
Rails 3.1 : Complex database query with Arel 2
Hi,
I''ve search for documentations on queries with Arel 2 but there is
pretty nothing and all I''ve found is for Arel 1 so I''ve run into
NoMethodError: undefined method `[]'' for
#<Arel::SelectManager:0x00000003f1b820> errors with join syntax.
My query is barely simple but involve nesting queries. I have 4 tables.
Assets, Deposits, Orders and OrderLines
2009 Mar 25
0
Optimise this association?
hey all
In my schema, Lesson is many to many with Asset (through join table
''elements''), which are also many to many with Resource (through join
table ''items''). This is all done with totally standard "has_many
:through" -
Lesson
has_many :elements, :dependent => :destroy, :order => :position
has_many :assets, :through => :elements,
2007 Dec 20
3
ActiveRecords Eager Loading
Hi,
I am doing an eager loading in ruby on rails using below statement
------------------------
Article.find(:all, :include => [:asset, :vote],
:conditions=>"assets.parent_id is null",
:order=>"stat_final_ranking desc", :limit=>20)
---------------------------------------
the above statement resulted in this expensive query.
2007 Jun 26
4
Can I stub a method on a belongs_to association:
describe Asset, " when destroyed" do
fixtures :assets, :videos, :sites, :publish_settings
before(:each) do
@asset = assets(:test_asset)
@mock_hook = mock("hook")
@asset.video.stub!(:hook).and_return @mock_hook # error occurs here
end
it "should call the delete hook" do
@mock_hook.should_receive(:update).with("test_video",
2010 Apr 05
0
Risk Assessment Application
I am going to be developing a Risk Assessment system for a secure
environment whose database will double as an asset management system.
Or at least the Risk Assessment stuff will be an outcropping of the
asset management system.
Has anyone had any experience with this or a similar project?
This is my first attempt at a Rails project after spending a few weeks
reading books and getting a general
2006 Jul 20
5
How can I make has_many prevent a delete that would lead to orphans?
e.g.
class Asset < ActiveRecord::Base
validates_presence_of :asset_number, :make, :model, :location,
:name, :serial_number
validates_numericality_of :asset_number
validates_uniqueness_of :asset_number
belongs_to :user
belongs_to :location
belongs_to :asset_type, :foreign_key => ''type_id''
end
class Location < ActiveRecord::Base
validates_presence_of :name
2007 Aug 30
3
has/belongs to many sql error
I have a model Asset which has_and_belongs_to_many :tags. Tag has only
one field, name. There is a table assets_tags which only has an
asset_id and a tag_id.
I can add a tag to one asset. If I try to add the same tag to another
asset though (asset.tags << tag) I get this error:
Mysql::Error: #23000Duplicate entry ''4'' for key 1: INSERT INTO
assets_tags (`tag_id`, `id`,
2005 Dec 20
0
validates_uniqueness_of on has_and_belongs_to_many
I am trying to create a model that allows only unique assets to be
added to a category. However, they could be added again to a different
category. Finally, an asset can be shared across many categories. So
my question is how do you check the uniqueness across a join table?
This does not compile....
has_and_belongs_to_many :categories, :foreign_key => ''asset_id''
2008 Mar 13
3
Refreshing a page gives a "stack level too deep" error.
I''m converting our app into restful rails. A couple of my classes
(Resource and Asset) have a has_many relationship with each other -
here''s the routes:
map.resources :assets, :has_many=>[:resources]
map.resources :resources, :has_many=>[:assets]
I''m getting something weird in my view pages. When i go to
/resources/4/assets
it works. I go to the page
2008 Aug 01
2
image_path without timestamp
Every time I use an asset tag helper, there is a parameter appended to
the end of my file name.
e.g. <input src="/images/search.gif?1213816620" type="image" />
From what I am reading, this appears to be a timestamp for caching
purposes. It works in most cases, but I want to use image_path to embed
a flash file.
.swf file in public/images/flash
e.g.
2008 Jun 25
1
"Complex" Eager Loads
Hey gang.
Is it possible to extend the eager load SQL at all? What I''m hoping
to do is eagerly load an associate that, in turn, joins in some data
from another table.
Many thanks,
James
--~--~---------~--~----~------------~-------~--~----~
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 Mar 31
2
Eager loading of polymorphic associations
Polymorphic associations work great until I try to do some eager
loading through :include. In my example, the interface name is
":imagehaver". Here''s my little eagerly loading find line:
Image.find(params[:id], :include => :imagehaver)
All it gives me is an ActiveRecord::EagerLoadPolymorphicError with no
further explanation. I haven''t been able to dig up anything
2008 May 08
1
Eager loading of association extensions
Hello all,
Is it possible to do eager loading of association extensions?
That is, the following code produces one SQL query:
cat = ProductCategory.find(:first, :include => :pricing_rules)
cat.pricing_rules
But if in ProductCategory I have an association extension like this:
has_many :pricing_rules do
def applicable()
find(:all).select(&:applicable?)
end
end
the
2008 Jun 11
1
Resourse route in namespace with prefix error
Ok so I have this route
map.namespace :trades do |trades|
trades.resources :buys, :path_prefix => ''/trades/:contract_id''
end
I want the contract_id variable to filter a list of buys
then I try to open this route http://localhost:3000/trades/1/buys
I get a strange error:
ActionController::RoutingError in Trades/buys#index
Showing trades/buys/index.html.erb where line
2012 Feb 26
0
Served asset /application.css - 304 Not Modified
Hi
I am thinking to hide warning that is ”Served asset /application.css -
304 Not Modified”.
How can I fix something if I change the settings?
I''ve run that is less than
server:
rails new myapp
cd myapp
rake db:migrate
rails s
client:
http://localhost:3000/books
warning:
Started GET "/assets/books.css?body=1" for 127.0.0.1 at 2012-02-26
14:48:35 +0900
Served asset /books.css
2006 Jan 19
0
Limited eager loads and conditions on the eager tables
Hi,
Why are limited eager loads and conditions on the eager tables incompatible?
Doing a find(:all) without :include causes a select * query to be generated,
which means the id fields everwrite each other if associated tables are
included using :joins.
But using :include, if conditions are placed on the tables listed in :joins
then Rails throws an exception when :limit is included too.
2009 Aug 07
2
paperclip model fails while when updating with no attachment
Hi all,
I have paperclip running in my rails environment. I setup a new model
just for paperclip called Assets so that I could upload multiple files
per item (even though I''m only using 1 attachment per item at the
moment). Everything works except for the following:
Updating an item record with no attachment in the form but having
PREVIOUSLY attached an asset while creating or updating.
2006 Jul 31
0
Patch for #3438: Eager loading doesn''t respect :order of associations
Hello all,
I still have a patch for #3438 (eager loading doesn''t respect
association orders); it passes all unit tests, and has additional unit
tests with full coverage. The patch is attached.
== The Bug ==
Author.find(1).posts != Author.find(1, :include => [:posts]).posts
if Author has_many :posts, :order => anything.
This means that either one must avoid eager loading or