Displaying 20 results from an estimated 500 matches similar to: "belongs_to with has_and_belongs_to_many"
2006 Jan 09
6
has_and_belongs_to_many :self
Hi all
I got the following class:
class Member < ActiveRecord::Base
has_and_belongs_to_many :buddies,
:class_name => ''Member'',
:join_table => ''members_have_buddies'',
:foreign_key => ''member_id'',
:association_foreign_key =>
2008 Mar 07
3
Boolean circles..
Hi,
This is just kindof a RoR question, but since you all potentially do
the same things as I do, I thought I''ll ask here..
Im trying to use the boolean type in the database. Migrations is no
problem, it even converts the 0/1 values from my import CSV to false
and true.
However, I cannot make the :conditions part of a find work:
Loading development environment (Rails 2.0.2)
>> c
2006 Aug 10
1
Convert datetime_select to Time object?
--------------------------
Question 1
--------------------------
I am dealing with a database that holds products and it has a datetime
field called "active_at". so I have the following for active_at:
<%= f.datetime_select :active_at %>
It gives me 5 different params:
params[:product][:active_at(1i)]
params[:product][:active_at(2i)]
params[:product][:active_at(3i)]
2006 Sep 09
2
why doesn't this work (setting attribute in "before_create")
Hi,
Can anyone spot why the below doesn''t work?
* I have a "created_by" column in my create table in the dB
* I have a "before_create" line, which definitely gets called
* I tried a few different ways to set the "created_by" attribute in the
model but it doesn''t seem to work, i.e. doesn''t appear in the database
2006 Mar 01
6
How to retrieve attributes from HABTM?
We have tables Users and Communities linked by has_an_belongs_to_many.
The join table Communities_Users has additional fields [ is_active,
is_blocked, join_date] etc. These are populated using
@user.push_with_attributes(:is_active => true,...).
Later on how do we update or retrieve the attributes in the link table
for a given user or a community with doing it explicitly using SQL?
Thanks,
2006 Dec 06
2
validates_uniqueness_of where scope euqals created_by "magic" field
I have the following ActiveRecord objects:
class Recipe < ActiveRecord::Base
has_many :ratings, :dependent => true
. . .
end
class Rating < ActiveRecord::Base
validates_uniqueness_of :created_by, :scope => :recipe_id
belongs_to :recipe, :counter_cache => true
. . .
end
The created_by field on Rating is implemented as a "magic" field
similar to this:
2006 Jul 24
0
Mongrel + BackgrounDRb + File Column = Upload Progress Bar?
Hi there,
I''ve been digging around trying to find some information (mostly examples)
on how one would handle a progress bar upload using BackgrounDRb and File
Column. I did read http://backgroundrb.rubyforge.org/ and Ezra''s blog of
course, but I still have a few questions.
I made a simple upload form (as a test) that is submitted to the
"upload_song" action.
def
2007 Nov 05
0
Authentication: is a guest a user or an "exception"?
Hi all
I''m currently implementing authentication/authorization in my app. Now
I''m wondering what''s the common way to handle a guest...
In fact, many of the visitors of my app will be anonymous users that
just want to read articles etc., but one can register as a member to
have some further possibilities. So far one can login as a member and
from this point on one has
2005 Nov 22
11
Building a conditions clause (for find) of multiple optional params?
I want to be able to find items according to various params - category_id, member_id, type_id,
rating, etc. What I have now is something like:
if(@params[''category_id''])
@items=Item.find(:all, :conditions=>["category_id=?", @params[''category_id''])
elsif(@params[''category_id''] and @params[''member_id''])
2007 Aug 03
0
acts_as_paranoid and Association Extensions (has_one troubles)
Hi... Isn''t there a proper way or hack/workaround for the following?
* For the example with unfortunate disabilities.. look below,,,
Usage of has_* (associationmethods) do {def with_deleted
AccociatedModel#with_scope} {Paranoid''s#find_with_deleted}...
The has_one associations give me a nil object when invoking it with
Model.association_OBJECT.with_deleted. Has_many does like
2006 Apr 03
3
Retrieving a record using created_by
Hello,
Thank you all in advance for your help with this.
Environment:
Windows XP Pro (Development only)
Ruby 1.84
Rails 1.1.0
SaltedHashLoginGenerator
Plugins: file_column, userstamp
I have a user table per the salted_hash_login generator. I have an
orders table that has a column named created_by that is updated by the
userstamp plugin. I am trying to retrieve all of the orders for a single
2005 Feb 07
0
Trying to Seed Maybe Bug?
Hi, trying to get rubytorrent to act as a seeder.
I''m instantiation the RubyTorrent::Bittorrent with a pre-created
MetaInfo object...
bt = RubyTorrent::BitTorrent.new(dtorrent.metainfo)
bt.on_event(self, :tracker_connected) { |s, url| puts "[tracker]
connected to tracker #{url}" }
I will attack the test file (just some random strings in a file)
and the torrent that was
2006 Feb 17
2
validate uniqueness of two fields
I have Proposals and Members and Members can vote for a proposal only once.
So, I have "Vote belongs_to :member, :proposal", but to make sure a member only votes
once, I want to make sure that there isn''t a vote in the db with that member_id and
proposal_id. I can just put the appropriate find in a vote.valid? but I wanted to make
sure I wasn''t missing a nice rails
2006 Jan 03
2
help me understand association attributes
I have a model with a belongs_to association. The first model is called
Thing and the associated model is User. I''m attempting to assign the user to
the thing.
To accomplish this I used a before_save method, like this:
class Thing < ActiveRecord::Base
belongs_to :created_by, :class_name => "User", :foreign_key =>
"created_by_user_id"
def before_create
2009 Jun 20
0
AssociationTypeMismatch
Am getting the following error:
Modul(#36555780) expected, got String(#21132310)
After doing a lot of research on the net, i found that i need to pass
on the id field somehow, but i dont really know how to do it.
Following is the model:
---------------------------------
class Modul < ActiveRecord::Base
belongs_to :modulable, :polymorphic => true
end
class Chapter < ActiveRecord::Base
2007 May 11
3
is_active?
Hey all, i''m rather new to rails and was curious if ActiveRecord
implemented anything like is_active where the delete functions would
just mark records as inactive, vs deleting rows. (similar to created_at,
etc). I need a history of transactions, and this is how I would code in
other languages. Any advice? Is there are smarter way to implement this?
Thanks in advance!
--
Posted via
2006 Jun 15
2
AJAX form inside table - error
Hello,
I need to put an AJAX, form such that it is inside a table, and spans across
few rows.
But, what I am noticing is that, while submitting the form, the data in the
fields is not submitted.
If I move the form outside the table or inside a cell, things work OK, but not
when the form is inside the table and spans few rows. This problem is only
with AJAX forms, regular forms work perfect. I
2006 Jan 29
9
Specify options with habtm
Hi all
I have the following models:
class member
has_and_belongs_to_many :disc_jockeys
end
class disc_jockey
has_and_belongs_to_many :members
end
The relation table is called disc_jockeys_members and has the following
fields:
disc_jockeys_members(disc_jockey_id, member_id, status)
So far, the field status can have values like valid, invalid, locked
etc., but it is not regarded yet by
2007 May 20
1
beating a dead horse - proper association selection
okay... i have two models
employee
- id
- username
order
- id
- number
- created_by
- approved_by
now created_by and approved_by are both id''s of employees. in most
cases, two different employees.
currently i do something like
//controller
@open_orders = Order.open_orders
//model
def self.open_orders
find(:all, :conditions => [''is_open = ?'', true],
2006 Sep 25
3
Subclasses - help required
Hello all and hoping for some insight
a project manger type of application, staff are assigned to projects,
but each staff has varied roles for different projects... STI does not
seem to be applicable here
Imagine a table staffs...
id int
name varchar
blah....
is_manager int 1
is_engineer int 1
is_producer int 1
and projects...
id
name
manager_id
engineer_id
producer_id
how is the best way