model

Rails Models and unique combinations

I have a Rails app which has a table called friendrequests. It looks like this: user1_id:integer user2_id:integer hasaccepted:boolean I'm creating an option to add friends, but a friendrequest can only be send once. So you cannot have something like this in the database's data: user1_id | user2_id | hasaccepted 1 | 2 | ...

Two columns must not equal each other in Rails

I'm creating a social network in Rails and I have a model like this: create_table "friendships", :force => true do |t| t.integer "user1_id" t.integer "user2_id" t.boolean "hasaccepted" t.datetime "created_at" t.datetime "updated_at" end The problem is that you cannot add yourself as friend, so I tried this in my...

Complex query in django

Hay, i have a quite complex query i cant get working in django. My model is called Car(), and i want to perform this query on it query = "SELECT *, ((ACOS(SIN("+user_lat+" * PI() / 180) * SIN(lat * PI() / 180) + COS("+user_lat+" * PI() / 180) * COS(lat * PI() / 180) * COS(("+user_lon+" - lon) * PI() / 180)) * 180 / PI()) * 60 * 1.1515)...

CakePHP newbie question: How do I duplicate a model and its related data?

How do I duplicate an existing model record? Put another way, how do I retrieve an existing model with related data, then save a COPY of that model AND data (both model and related data are copied)? This is trivial using simple SQL, but I want to do it using CakePHP best practices. ...

Rails ActiveRecord updating fields

My Example: class Category < ActiveRecord::Base has_many :tags, :as => :tagable, :dependent => :destroy def tag_string str = '' tags.each_with_index do |t, i| str+= i > 0 ? ', ' : '' str+= t.tag end str end def tag_string=(str) tags.delete_all Tag.parse_string(str).each { |t| tags.build(:tag...

Overwrite data and setData in Qt's QFileSystemModel

Hi, What I'am trying to do: Overwrite QFileSystemModel's setData and data to implement Caching of pictures in the shown directory. I use a QListView for testing purpose. Here is the relevant code: My Class with QFileSystemModel as parent: .h-file: #ifndef QPICSINFILESYSTEMMODEL_H #define QPICSINFILESYSTEMMODEL_H #include <QFileSy...

CakePHP Model: COUNT(*) in Containable

I have a CakePHP 1.3 app and really enjoy the Containable behavior for fetching data. Let's assume I have Posts in one-to-many relationship with Comments. I use Containable to query (for pagination) a list of all Posts and the belonging Comments. But I'm only interested in how many Comments each Post has. I did not found any way to achi...

How to avoid updating update_at flag while updating associated model in active record?

My association to models as follows People model belongs_to :category has_one :account, :through => :category category model belongs_to :account has_many :bookings account model has_many :categories Level model accepts_nested_attributes :peoples I wrote @level.update_attributes(params[:level]) in Le...

Cache problems when updating an object from another model

I have a problem with making changes to an object from within another model as well as within the object's model. I have the following models: class Foo < ActiveRecord::Base has_many :bars def do_something self.value -= 1 # Complicated code doing other things to this Foo bars[0].do_other save! end end class Bar...

Creating a hybrid-model (with bits of other models) in ASP.NET MVC?

I've created an Audit table for an ASP.NET MVC application to track key changes and actions. I want to present the contents of this table to authorized users in an easily readable format on the view. The Audit table is (simplified) like so: ID (int) | StaffID (int) | Action (string) | Timestamp (datetime) ------------------------------...

How to bind form fields to model properties with different names?

Hello. I've got a search form that I want to use short query string parameters for (e.g. ?q=value&s=whatever&c=blah) and I'd like to use MVC model binding to get those parameters into my controller action. I can create a type that mirrors these short names, but I'd rather have a type that has more sensible names (e.g. q = Query, s = Sor...

Return selection of fields from a Model in django

Hay guys, i want to use something like this users = User.objects.all() but i only want to return a couple of fields for each result, say 'name' and 'email'. This data is going t be turned into JSON data, and some fields in my model are sensitive. How would i do this in django? ...

Where should I store virtual/calculated/complex object fields in my models?

I have models corresponding to database tables. For example, the House class has "color", "price", "square_feet", "real_estate_agent_id" columns. It is very common for me to want to display the agent name when I display information about a house. As a result, my House class has the following fields: class House { String color; Do...

3DS model loading - tree/hierarchies

I am using the 3DS loader here: http://www.flipcode.com/archives/Another_3DS_LoaderViewer_Class.shtml It does a good job of loading and rendering the model, however it lacks any sense of heirarchy. As a result, all the objects in the model render at the origin. In the code under: void Model_3DS::MainChunkProcessor(long length, long fi...

Implementing search engine into website

Hi, I want to develop a website with its own search engine. I would like to use some sort of web framework for all this development, like Django or Rails. The search would be based on vector space model (data is represented as term-by-document matrix). Everything would be running on one server, there would be no extra server for informa...

An Emacs alternative which exposes a text model to a scriptable environment?

Hello, everybody out there! I'm currently seeking for a technical solution to create a nice literate programming environment. Unfortunately, most editors are too much hard coded, and their functionalities just cover most famous needs, and can't cleanly cover special needs. I came to Emacs (later after some others), but I also came to n...

CakePHP HABTM relations listing

I'm have quite a problem while trying to make a list (for the admin section) of HABTM relations. Here's the deal: permissions: id, name; users: id, username; permissions_users: permission_id, user_id Permission HasAndBelongsToMany User I want to make a listing like such: User.id | User.username | Permission.id | Permission.name 1 | J...

Rails: How to treat some fields of model info independently? Eg. Account vs. Profile information.

I have a User model with the usual information (login, email, name, location, etc). However, when users decide to edit their information, I'd like to separate the fields to be edited according to the appropriate concerns. For example, I'd like to have Name, Bio and Location to be edited on a Profile page or tab, and login, email and pa...

Referenced Model Loading in Google App Engine

Hello, In Python, say I've got a model of class A that has a ReferenceProperty b to model class B, which has a ReferenceProperty c to model class C. Assuming an instance of A already exists in the datastore, I can get it by saying: q = A.all() a = q.get() In this scenario, how does entity loading work? Is a.b retrieved when a is ret...

I'm having trouble understanding this really simple PHP code. Please help?

Here's the code: <?php class Order extends Zend_Db_Table_Abstract { protected $_name = 'orders'; protected $_limit = 200; protected $_authorised = false; public function setLimit($limit) { $this->_limit = $limit; } public function setAuthorised($auth) { $this->_authorised = (bool) $auth; } public function insert(arra...