The database problem is solved. My limited understanding pins the failure on my pre-set “id” attribute. Currently I’m setting :id manually after calling the superclass (ActiveRecord::Base) constructor and before saving the object, which appears to work.
A second problem occurred when I saved objects more than once, specifically when the ID is the same but non-key fields changed. I got around this by doing an update if the ID exists in the database and a save if it does not. This results in an extra query with every save, but caching is done so rarely that this should not make a difference
app/models/person.rb constructor:
def initialize( person_info )
if person_info.instance_of? Basewrapper::Recordwrapper
hash = person_info.get_hash
id = hash["id"]
super hash
write_attribute :id, id
if Person.exists? id
update
else
save
end
end
end
Timeentry, Project and Company look very similar to this. To create basic associations, I declare that Project and Person “has_many :timeentries” and Timeentry “belongs_to” Project and Person.
I added the custom attribute “api_user” to the basecamp objects. This will allow me to clear the cache for each user at the end of the session.
I also added the static function “update_cache(url, login, pass, use_ssh)” to every model object. The cache will be initialized when the user authenticates, and this will be our only basecamp interaction. All subsequent data is read from my local database.
Where this is going:
Once the model layer is complete, I will write the controller layer to generate graphs of hours per person, hours per project and (if I have time) a pivot view of hours by person by project.
