Closed durchanek closed 15 years ago
Wow, I'm using this gem, I've forked it, and have just added one of the features you suggested and plan to add the second. I'd like to be able to deal with multiple levels of hierarchy with associated columns.
I'm considering lots of different ways of specifying associated columns:
extjs_fields :field, :field2, :parent => [:field1, :field2]
extjs_fields :field, :field2, [:parent, :field1, :field2, [:grand_parent, :field1]]
extjs_fields :field, :field2, 'parent.field1', 'parent.field2'
extjs_fields :field, :field2, :parent => {:field1 => ''parent_field1', :field2 => 'parent_field2'}
That's awesome :-) I was considering the same way which ActiveRecord uses now eg. for association eager loading - it would be developer-friendly for write them without much thinking. I think that your first example is perfect.
Yea, we need some smarter mechanism for associations.
Also, I'd like to be able to override fields when calling #to_record.
eg:
User.first.to_record(:username, :email)
I'm doing a big refactor. I'll soon see about the mapping property
Great news, let me know if I can help.
Implemented mapping. Need to do some tests before I push new Gem version
Pushed version 0.2.7 with mapping support, with help from Daniel Beardsley.
Hello, just tested new version and I was unable to get it work. It looks like some weird stuff in extjs_record(_fields): puts "1" + self.extjs_record_fields.inspect associations = self.extjs_associations puts "2" + self.extjs_record_fields.inspect # extjs_record_fields are gone here - only array of column names remains columns = self.extjs_columns_hash fields = fields.empty? ? self.extjs_record_fields : self.process_fields(_fields) pk = self.extjs_primary_key I was pretty much unable to find error here, because extjs_associations method does not touch extjs_record_fields at all.
What's your Model setup look like? Rails 2.3.4?
I've figured out a testing strategy and created a test-db with 2 models, User and Person. I pushed some simply Model tests to github.
OK, I got it working, event mapping generates OK. But I had to comment out most of associations, my WORKING code looks like this
class Journalist < ActiveRecord::Base
belongs_to :position, :class_name => 'JournalistPosition', :foreign_key => :position_id
# has_and_belongs_to_many :magazines
# has_and_belongs_to_many :groups, :class_name => 'JournalistGroup', :join_table => :journalist_groups_journalists
# has_many :item_lends
# has_many :item_lend_wishes
extjs_fields :name, :surname, :position => [:name]
end
I have included Extjs::Model to ActiveRecord::Base, so include line is missing here. When I uncomment has_and_belongs_to_many :magazines than error is back
I added a HABTM test in Github and it didn't fail. Have a look at test/model_test.rb I set up the test table and associations in test/test_helper.rb
OK, I found it - it was because of my inclusion of Extjs::Model in initializer.
Just tried to use extjs-mvc gem and i found it really helpful. But I am missing mapping support for JsonStore which I think is needed to correctly handle associations. My idea is to alter extjs_fields call so it can handle nested columns, something like this:
Another possibility which came to my mind is to have multiple configurations like this:
This will not probably be backwards-compatible but can be useful when loading data depending on security setting/UI component/etc. I believe I can handle this on my own but I would like have this "approved" for inclusion before coding :-)