On Domingo, 12 de Julio de 2009 22:37:41 Paul Taylor escribió:
> In playing around a little with SQL, I've found that I can perform
> this query that gets me close to what I'd like, with a bit of
> processing:
>
> select stores.id, stores.name, utms.name from stores left join utms on
> stores.id = utms.store_id
>
> The results from sqlite shows:
> 1|167|
> 2|191|02:05:06:08:07:08
>
> In this situation, store 167 does not have a UTM assigned, and store
> 191 does. I'd only want the records that had empty values returned
> for the utms.name column. (Except that I'd also want the one that was
> assigned to this particular UTM)
>
> I've found options_for_association_conditions, which looks like what I
> want to filter this, but I'm not familiar enough with Ruby to
> translate this SQL into what I want... (though I'd prefer a better,
> more general API supported way)
>
> Any help there would be greatly appreciated.
Try with {'utms.store_id' => nil}:
def options_for_association_conditions(association)
if association.name == :store
{'utms.store_id' => nil}
else
super
end
end
>
> As a stop gap, I've implemented some validations to make sure the same
> store doesn't end up getting two different UTMs assigned to it, like
> so:
> validates_uniqueness_of :store_id, :allow_nil => true
>
--
Sergio Cambra .:: entreCables S.L. ::.
Mariana Pineda 23, 50.018 Zaragoza
T) 902 021 404 F) 976 52 98 07 E) [email protected]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/activescaffold?hl=en
-~----------~----~----~----~------~----~------~--~---