Rails Model has_many with multiple foreign_keys

Found a simple answer on IRC that seems to work (thanks to Radar): class Person < ActiveRecord::Base belongs_to :father, :class_name => ‘Person’ belongs_to :mother, :class_name => ‘Person’ has_many :children_of_father, :class_name => ‘Person’, :foreign_key => ‘father_id’ has_many :children_of_mother, :class_name => ‘Person’, :foreign_key => ‘mother_id’ def children children_of_mother + children_of_father end end

edit uri of existing resource using jena

As you’ve found resources are immutable. You can bring about the same effect using ResourceUtils.renameResource(resource, newName). This goes through your model removing statements mentioning the old resource and adding the equivalents with the new, which is as close as you’re going to get to a rename. Example: Resource renamed = ResourceUtils.renameResource(originalResource, “http://example.com/new”);

Rails gem rails3-jquery-autocomplete: How do I query multiple fields

Your pseudo attribute works only on records already retrieved, but it has no bearing on searching for records. Probably the easiest solution is a named named scope like: scope :search_by_name, lambda { |q| (q ? where([“first_name LIKE ? or last_name LIKE ? or concat(first_name, ‘ ‘, last_name) like ?”, ‘%’+ q + ‘%’, ‘%’+ q … Read more

Django self-recursive foreignkey filter query for all childs

You can always add a recursive function to your model: EDIT: Corrected according to SeomGi Han def get_all_children(self, include_self=True): r = [] if include_self: r.append(self) for c in Person.objects.filter(parent=self): _r = c.get_all_children(include_self=True) if 0 < len(_r): r.extend(_r) return r (Don’t use this if you have a lot of recursion or data …) Still recommending mptt … Read more

ValueError – Cannot assign: must be an instance

You don’t need to pass the department id, the instance itself is enough. The following should work just fine: new_team = Team( nickname = team_name, employee_id = employee_id, department_id = Department.objects.get(password = password, department_name = department_name)) Just a note: don’t ever name your foreign fields something_id. That something is enough. Django is meant to make … Read more