On Wednesday 24 February 2010 10:02:15 Sergio Cambra .:: entreCables S.L. ::.
wrote:
> > This named_scope in CatalogItem works just fine in the console:
>
> But does association work in console? I can't help you with your
> association because I don't know your schema neither your models.
markers, conjugates, fragments, isotypehs and origins are all just id/name
tables with simple "has_many :catalog_items" in the model (markers also
acts_as_nested_set and thus includes parent_id, lft, rgt).
mysql> describe catalog_items;
| Field | Type | Null | Key | Default | Extra |
| id | int(11) | NO | PRI | NULL | auto_increment |
| marker_id | int(11) | YES | | NULL | |
| catalognumber | varchar(255) | YES | | NULL | |
| concentration | float | YES | | NULL | |
| amount | float | YES | | NULL | |
| conjugate_id | int(11) | YES | | NULL | |
| manufacturer_id | int(11) | YES | | NULL | |
| isotypel_id | int(11) | YES | | NULL | |
| origin_id | int(11) | YES | | NULL | |
| created_at | datetime | YES | | NULL | |
| updated_at | datetime | YES | | NULL | |
| klone | varchar(255) | YES | | NULL | |
| isotypeh_id | int(11) | YES | | NULL | |
| fragment_id | int(11) | YES | | NULL | |
class CatalogItem < ActiveRecord::Base
belongs_to :conjugate, :isotypel, :isotypeh, :manufacturer, :marker, :origin,
:fragment
# has_many :catalog_items
has_many :isotests, :foreign_key => nil, :class_name => "CatalogItem",
:finder_sql => 'SELECT * FROM catalog_items WHERE marker_id=1 AND
conjugate_id=#{conjugate_id} AND fragment_id=#{fragment_id} AND
isotypeh_id=#{isotypeh_id} AND origin_id=#{origin_id}'
named_scope :isotypecontrol,
lambda { |conjugate, fragment, isotypeh, origin|
{
:include => [:marker, :conjugate, :fragment, :isotypeh, :origin],
:conditions => ['markers.name= "Isotype Control" AND
catalog_items.conjugate_id = ? AND catalog_items.fragment_id = ? AND
catalog_items.isotypeh_id = ? AND catalog_items.origin_id = ?', conjugate,
fragment, isotypeh, origin]
}
}
The controller now contains 2 links for the same purpose:
config.nested.add_link("Isotype Control", [:catalog_items])
config.nested.add_link("Isotests", [:isotests])
I haven't yet figured out how to get the parent_record using your action_link-
approach and sticked with the old beginning_of_chain for now. So now I've
tried to use both named_scope and an association with finder_sql - it seems
both should be suitable for my problem and are mutually exclusive?
Using the isotests association, I get
"Unknown column 'isotests_catalog_items.catalog_item_id' in 'on clause'".
Using the named scope with an added "has_many :catalog_items" still yields
"Unknown column 'catalog_items_catalog_items.catalog_item_id' in 'on clause'"
I'm confused, not even the manual finder_sql seems to help. Thought I'd need
to add an association without a foreign key, but how is that possible?
thanks for your help!
ben
--
You received this message because you are subscribed to the Google Groups
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/activescaffold?hl=en.