Displaying 20 results from an estimated 30000 matches similar to: "optional has_one association"
2008 Feb 19
0
Issue with Observers and has_one association...
Hey Guys,
I''m getting a peculiar bug working with Observers and has_one
associations. When a has_one association is invoked by an Observer it
always returns null. I looked in the development.log file and the SQL
for the has_one association isn''t even being executed. On the other
hand, when I replace the has_one association with just a hand crafted
method, it does get called
2008 Sep 29
1
has_one :through with :source. How to alias association?
Hi to everyone,
I have the following models:
class Attachment < ActiveRecord::Base
has_attachment :content_type => [:image, ''application/pdf''],
:max_size => 3.megabytes,
:path_prefix => ''../private/attachments'',
:storage => :file_system,
:processor => :rmagick,
2009 May 25
4
after_create and has_one association bug?
Hello,
I''ve come across an issue that I''m sure is a bug when using after_create
with a has_one association, but I''m not 100% certain if I''m missing
something.
This is pretty much exactly the code I''m using. Two simple classes
(Account and Contact) and I create the contact after I create an account
(via after_create). I''m not passing in a
2007 Mar 01
0
association extensions - has_one
Hi,
I''m struggling with something that must be very common pattern, and
want to do it the correct rails/ruby way but am a bit dense !
I have users - an admin user, registered users and a guest user (using
ModelSecurity)
For many of linked associations I want the admin to be able to list or
edit all instances, the registered user only their own one and guest
none at all.
So somehow I
2014 Apr 19
0
How to has_one/belongs_to association only return the objects unassociated in combobox?
I have two models (Car and Driver) and a combobox to select which driver
belongs to which car. I want the combobox just show the objects that have
not yet been associated.
# vehicle belongs_to: driver
# driver has_one: vehicle
# simple_form # vehicle/_form.html.haml
= f.association: driver, label_method: :name, value_method: :id
How to ensure validation before saving, to avoid problems of
2010 Mar 29
0
Polymorphic association and has_one retrieval issues
class Address < ActiveRecord::Base
belongs_to :addressable, :polymorphic => true
end
class Client < ActiveRecord::Base
has_one :address, :as => :addressable
end
Now I''am able to create a correct entry in the db for address with
addressable_id = 1#client_id
addreassable_type = ''Client''
but when I retrieve
client = Client.find(1) --> return client
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
2012 Aug 17
3
Rails doesn't validate create_model or build_model (has_one association)
I''ve got User has_one Shop. Rails is not validating when I tried
create_shop or build_shop, neither in the browser nor the rails console.
My code:
class Shop < ActiveRecord::Base
attr_protected :user_id
belongs_to :user
validates_presence_of :name, :primary_address, :city, :country_code,
:currency
end
class ShopsController < ApplicationController
before_filter
2006 May 16
1
saving a has_one association question
Hiall,
Say I have
class User
has_one :community
end
class Community
belongs_to :user
end
Will the following work and both save user and community if validation
doesn''t fail?
user = params[:user]
user.community = params[:community]
user.save
Or do I have to do something like the following
user = params[:user]
if user.save
user.community = params[:community]
end
to be on the
2010 May 05
0
Auto_complete with has_one association
Hi,
Have an issue with the rails auto complete, it works fine but I don''t
know how to find the id element search in the textfield.
Here is what I''ve done:
<%= text_field_with_auto_complete :user, :ville_name, { :size => 15 },
{ :url => formatted_villes_path(:js), :method => :get, :param_name =>
''search'' } %>
Model:
class User <
2013 Mar 05
4
searching model and has_one association
Howdy.
I have these models:
User, field "mundane_name"
user has_one :instructor_profile (may or may not exist)
instructor_profile, field "sca_name"
belongs_to :user
I would like to craft a search on these fields, which is effectively this,
but in one go:
matching_users = User.where("mundane_name ILIKE ?", "%#{target}%")
matching_profiles =
2008 Sep 16
3
has_one :through eager-loading problem
I have a problem with the :include option in find for my
has_one :through association.
I have Users, Profiles and Customers, all connected to each other with
a has_one :through => :membership association like this:
class Profile < ActiveRecord::Base #could also be user or customer
has_one :membership # i saw an acrticle of Ryan about
has_one :through, there this would be has_many, is
2006 Nov 04
0
one to many relationship; has_one
I''m new to ruby and rails and as a result am a bit lost on implementing
a one to many relationship. In my DB I have 2 tables contents and
locations, contents contains the foreign key location_id. I generated a
content and a location model using rails scripts and then edited the
models as follows
class Content < ActiveRecord::Base
has_one :location
end
class Location <
2012 Nov 19
0
has_one :through NoMethodError: undefined method `klass' for nil:NilClass when doing class_name on reflection
Not sure if this is expected or not. Only happened with a has_one :through
I had setup. (Workaround is just to remove it and go through the
association manually vs has_one ..., through: .)
Not a big deal if no one has time to look at it, as it''s not a big enough
deal to look into a fix on our side.
In Rails (3.2.9) console if I do:
MyModel.reflections.each {|name,reflection|
2006 Sep 27
5
Question about has_one
I have a question about regarding the use of ''has_one'' in this scenario:
Schema:
User
----
id
first_name
last_name
UserMessage
----
user_id
message_id
Message
----
id
Assuming business rules dictate that a Message can have at most ONE User
(let''s assume a message can be created without a user associated to it),
these are my questions:
1) How would I use has_one
2006 Aug 09
0
association dows not grt foreign key
I have a 1 to 1 relationship using a similar example as below
(has_one, belongs_to)
but when I do the save, the foreign key of the child object is not set
to the id of the parent object in the relation ship
any ideas?
cheers
dion
---------------------------------
class Person < ActiveRecord::Base
has_one :address
validates_presence_of :email
---------------------------------
end
2006 Aug 09
0
Re: association does not get foreign key
On 8/10/06, Dion Hewson <dionhewson@gmail.com> wrote:
>
> I have a 1 to 1 relationship using a similar example as below (has_one, belongs_to)
>
> but when I do the save, the foreign key of the child object is not set to the id of the parent object in the relation ship
>
>
> any ideas?
>
> cheers
>
> dion
>
> ---------------------------------
>
>
2006 Jun 21
1
ActiveRecord has_one default value
My apologies if this is a dumb question, but I''ve searched around and
haven''t been able to come up with a solution.
Is there a way when specifying a has_one association to specify a
default value for an object if data is missing in the child table. For
instance:
class Student
has_one :university
end
if no university is associated to the student in the database, I would
2007 May 29
1
YAML fails when has_one is null
My model has_one :association
If I call model.to_yaml (or y model) in the console, and the
association is nil, I get a yaml error. Anyone else get this? Is
this a confirmed bug?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to
2006 Jun 19
0
has_one frustrations, please help!
Hi everyone. I''ve been bending my head around a has_one association for
about 3 hours now and I can''t get it to work. I''m pretty sure it''s not
something I''m overlooking anymore. Here''s the essential part of the
schema I''m working with:
-----
t :topics
c :id
c :last_post_id
t :posts
c :id
c :topic_id
-----
Topics are simply named