On Sunday, September 24, 2017 at 8:23:05 PM UTC-7, [email protected] wrote:
>
> I created 3 tables. Including 2 N-N tables (subjects, classes )and 1 
> relation table(classes_subjects)
>   up do
>     run 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp"'
>
>     create_table(:classes) do
>       uuid :id, default: Sequel.function(:uuid_generate_v4), primary_key: 
> true
>
>       uuid :kindergarten_id, null: false
>       uuid :grade_id, null: false
>
>       String :name, size: 255, null: false
>       String :description, size: 1000, text: true
>
>       DateTime :deleted_at
>       DateTime :created_at, null: false, default: Sequel::CURRENT_TIMESTAMP
>       DateTime :updated_at, null: false, default: Sequel::CURRENT_TIMESTAMP
>     end
>
>     add_index :classes, :kindergarten_id, where: "deleted_at IS NULL"
>     add_index :classes, :grade_id, where: "deleted_at IS NULL"
>   end
>
>   down do
>     drop_table(:classes)
>   end
>
> end
>
>
>   up do
>     run 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp"'
>
>     create_table(:subjects) do
>       uuid :id, default: Sequel.function(:uuid_generate_v4), primary_key: 
> true
>
>       uuid :teacher_id, null: false
>       uuid :kindergarten_id, null: false
>
>       String :name, null: false, size: 255
>       String :description, size: 1000, text: true
>       DateTime :start_time
>       DateTime :end_time
>       String :range, default: 'class' # ['class', 'grade']
>
>       DateTime :deleted_at
>       DateTime :created_at, null: false, default: Sequel::CURRENT_TIMESTAMP
>       DateTime :updated_at, null: false, default: Sequel::CURRENT_TIMESTAMP
>     end
>
>     add_index :subjects, :teacher_id, where: "deleted_at IS NULL"
>     add_index :subjects, :kindergarten_id, where: "deleted_at IS NULL"
>   end
>
>   down do
>     drop_table(:subjects)
>   end
>
> end
>
>   up do
>     run 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp"'
>
>     create_table(:classes_subjects) do
>       uuid :id, default: Sequel.function(:uuid_generate_v4), primary_key: 
> true
>
>       uuid :subject_id, null: false
>       uuid :class_id, null: false
>
>       DateTime :created_at, null: false, default: Sequel::CURRENT_TIMESTAMP
>     end
>
>     add_index :classes_subjects, :subject_id
>   end
>
>   down do
>     drop_table(:classes_subjects)
>   end
>
> end
>
>
>
> When I use 'Subject.association_join(:classes).where(class_id: 
> 'dsadadsadsadadafasfafaf')' .It errors like:
> Enter code here...NoMethodError: undefined method `dataset' for 
> Class:Class
> As the 'NoMethodError' refers.Do I need to change my table name 'classes' 
> into 'clazzes' ?
>

No, the table name is not important, it's the model name that is important. 
 You probably need to specify the :class option to the classes association 
for Subject to the correct model class name, which can't be Class as ruby 
already uses Class.

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 https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to