Also, here is the actual SQL.

FYI - I'm pretty sure the group by is only because of the order by which is 
not in the *query.rb* gist I gave but is in the 
*original_datamapper_classes.rb* gist...hence all the properties also being 
listed.  *So that part of the query you can ignore.*

*DataMapper SQL*
SELECT `people`.`id`, `people`.`created_date`, ......(all properties).... 
FROM `people` 
INNER JOIN `group_people` ON `people`.`id` = `group_people`.`person_id` 
INNER JOIN `groups` ON 
    `group_people`.`group_id` = `groups`.`id` 
    AND 
    `group_people`.`group_school_id` = `groups`.`school_id` 
WHERE (`groups`.`ems_type` = 'Ready' AND `people`.`first_name` = 'Bob') 
GROUP BY `people`.`id`, `people`.`created_date`,  ......(all 
properties)....  
ORDER BY `people`.`id`

*Sequel SQL*
SELECT * FROM `people` 
WHERE 
    ((`group` IN (SELECT * FROM `groups` WHERE (`ems_type` = 'Ready'))) 
    AND 
    (`first_name` = 'Bob'))


On Thursday, July 23, 2015 at 4:19:08 PM UTC-7, [email protected] wrote:
>
> Thanks.  Now I get the following error with the query in the *query.rb* 
> from the gist
>
> *Sequel::DatabaseError: Mysql2::Error: Operand should contain 1 column(s)*
>
> Also, I get a lot of these during my rake test now...
>
> *Sequel::ForeignKeyConstraintViolation: Mysql2::Error: Cannot add or 
> update a child row: a foreign key constraint fails (`core`.`group_people`, 
> CONSTRAINT `group_people_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES 
> `people` (`id`))*
>
> Which are usually triggered by....
>
> *g_instance = Group.new(data)*
> *p_instance = Person.new(data)*
> *p_instance **.add_group(**g_instance**)*
>
>
> On Thursday, July 23, 2015 at 3:47:33 PM UTC-7, Jeremy Evans wrote:
>>
>> On Thursday, July 23, 2015 at 2:15:02 PM UTC-7, [email protected] wrote:
>>>
>>> Everything has been going well in my upgrade, 1 project done and a 
>>> couple to go.  However, I've poured through the associations info in the 
>>> documentation and narrowed in on this one 
>>> <http://sequel.jeremyevans.net/rdoc/files/doc/association_basics_rdoc.html#label-many_to_many+and+one_through_one>.
>>>  I'm 
>>> having a hard time making my queries and models jive with the generated 
>>> migration file (a "common query" generator would be awesome).  The 
>>> migration came from a schema that was originally made by DataMapper.  
>>>
>>> This gist <https://gist.github.com/Nogbit/45b21c2c9c5340cc1afd> has all 
>>> the necessary code with the goal being........with *person.rb* and 
>>> *group.rb* have a query that works in *query.rb*.  The migration that 
>>> is used is* 001_migration.rb* which had its tables originally generated 
>>> from the classes in *original_datamapper_classes.rb* (which also has 
>>> the original DataMapper query).  
>>>
>>> While I get the error noted in *query.rb*, I believe that error to not 
>>> be in the right context because either the query itself is wrong, or, my 
>>> associations are wrong in the models.  Please advise if you have the time.
>>>
>>
>> You are using composite primary key on Group, so you have to use 
>> composite association keys:
>>
>> Person.many_to_many  :groups,
>>        :left_key=>:person_id,
>>        :right_key=>[:group_id, :group_school_id],
>>        :join_table=>:group_people
>>
>> Group.many_to_many :people,
>>        :left_key=>[:group_id, :group_school_id],
>>        :right_key=>:person_id,
>>        :join_table=>:group_people
>>
>> That should hopefully fix it.
>>
>> Thanks,
>> Jeremy
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to